spring数据elasticsearch:带有注释的设置和映射配置不起作用

Rub*_*bén 8 elasticsearch spring-data-elasticsearch

我正在将嵌入式Elasticsearch与Spring Boot结合使用,并且尝试使用批注来配置设置和映射。我遵循了该教程,该教程说明了如何实现对多个字段的搜索。无论如何,我已经定义了settings.json和mappings.json在我的文档实体所描述的在这里,但它好像它不读文件,因为卷曲荷兰国际集团的映射关系中的文件定义不返回相应的配置。

索引是通过春季批处理执行的。它从数据库读取数据并将其写入elasticsearch。这很完美。

当我向http:// localhost:9200 / profile / _search发出POST请求时,没有任何结果(应该返回7项):

{
   "size": 10,
   "query": {
       "match": {
       "_all": {
           "query": "user male",
           "operator": "and"
       }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

如果我将查询更改为“ user5”,它将使用该昵称返回用户。

如果有人可以给我提示,我将不胜感激。配置有什么问题?

配置

@Configuration
@EnableElasticsearchRepositories(basePackages ="com.company.searchengine.repository")
public class ElasticSearchConfiguration {
    @Value("${elasticsearch.clustername}")
    private String esClusterName;

    @Bean
    public ElasticsearchOperations elasticsearchTemplate() throws IOException {
        return new ElasticsearchTemplate(nodeBuilder().local(true).clusterName
            (esClusterName).node()
            .client());
    }
}
Run Code Online (Sandbox Code Playgroud)

文件

@EqualsAndHashCode(of = "uuid")
@ToString(exclude = "uuid")
@NoArgsConstructor(onConstructor = @__({@JsonCreator}))
@Getter
@Setter
@Document(indexName = "profiles", type = "profile", createIndex = false)
@Setting(settingPath = "/settings/settings.json")
@Mapping(mappingPath = "/mappings/mappings.json")
public class IndexedProfile {
    @Id
    @NonNull
    private String uuid;
    @NonNull
    //@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
    private String nickname;
    @NonNull
    //@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
    private String gender;
    //@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
    private String about;
    private GeoPoint location;
    @Field(type = FieldType.Date, format = DateFormat.year_month_day)
    private Date birthdate;
}
Run Code Online (Sandbox Code Playgroud)

批处理作业

@Override
public void write(List<? extends IndexedProfile> items) throws Exception {
    List<IndexQuery> indexQueries = items.stream()
            .map(item -> new IndexQueryBuilder().withObject(item).withId(String.valueOf(item.getUuid())))
            .map(builder -> builder.withType(DOCUMENT_TYPE))
            .map(builder -> builder.withIndexName(INDEX_NAME + runId))
            .map(IndexQueryBuilder::build)
            .collect(Collectors.toList());

    this.elasticsearchTemplate.bulkIndex(indexQueries);
}
Run Code Online (Sandbox Code Playgroud)

设定

{
  "settings": {
       "analysis": {
           "filter": {
               "nGram_filter": {
                  "type": "nGram",
                   "min_gram": 2,
                   "max_gram": 20,
                   "token_chars": [
                        "letter",
                        "digit",
                        "punctuation",
                        "symbol"
                    ]
            }
        },
        "analyzer": {
             "nGram_analyzer": {
                 "type": "custom",
                 "tokenizer": "whitespace",
                 "filter": [
                      "lowercase",
                      "asciifolding",
                      "nGram_filter"
                 ]
        },
        "whitespace_analyzer": {
            "type": "custom",
            "tokenizer": "whitespace",
            "filter": [
                  "lowercase",
                  "asciifolding"
             ]
         }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

对应

{
  "mappings": {
      "profile": {
          "_all": {
               "index_analyzer": "nGram_analyzer",
               "search_analyzer": "whitespace_analyzer"
           },
           "nickname": {
                "type": "string",
                "index": "not_analyzed"
           },
           ....
       }
  }
Run Code Online (Sandbox Code Playgroud)