我正在尝试在我的应用程序中使用ElasticSearch进行全文搜索,并且现在我正在尝试使用自动完成分析器:
{
"settings": {
"number_of_shards": 1,
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 20
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
}
}
由于我的应用是使用Spring构建的,我决定使用Spring-data-elasticsearch,并按照以下方式映射实体:
@Document(indexName = "estabelecimento")
@Setting(settingPath = "/elasticsearch/autocomplete-analyser.json")
public class ESEstabelecimento {
private Long id;
@Field(type = FieldType.String, indexAnalyzer = "autocomplete")
private String nome;
private String razaoSocial;
private String tipoEstabelecimento;
@Field(type = FieldType.Object)
private ESCidade cidade;
}
然而,Elasticsearch没有加载自定义分析器:
[DEBUG] org.elasticsearch.action.admin.indices.mapping.put - [Magus] 在索引[[estabelecimento]],类型[esestabelecimento]上放置映射失败 org.elasticsearch.index.mapper.MapperParsingException: 找不到字段[nome]的分析器[autocomplete] at org.elasticsearch.index.mapper.core.TypeParsers.parseField(TypeParsers.java:220) ~[elasticsearch-1.5.2.jar:na] at org.elasticsearch.index.mapper.core.StringFieldMapper$TypeParser.parse(StringFieldMapper.java:153) ~[elasticsearch-1.5.2.jar:na] at org.elasticsearch.index.mapper.object.ObjectMapper$TypeParser.parseProperties(ObjectMapper.java:290) ~[elasticsearch-1.5.2.jar:na] at org.elasticsearch.index.mapper.object.ObjectMapper$TypeParser.parseObjectOrDocumentTypeProperties(ObjectMapper.java:214) ~[elasticsearch-1.5.2.jar:na] at org.elasticsearch.index.mapper.object.RootObjectMapper$TypeParser.parse(RootObjectMapper.java:136) ~[elasticsearch-1.5.2.jar:na] at org.elasticsearch.index.mapper.DocumentMapperParser.parse(DocumentMapperParser.java:211) ~[elasticsearch-1.5.2.jar:na] at org.elasticsearch.index.mapper.DocumentMapperParser.parseCompressed(DocumentMapperParser.java:192) ~[elasticsearch-1.5.2.jar:na] at org.elasticsearch.index.mapper.MapperService.parse(MapperService.java:434) ~[elasticsearch-1.5.2.jar:na] at org.elasticsearch.cluster.metadata.MetaDataMappingService$4.execute(MetaDataMappingService.java:505) ~[elasticsearch-1.5.2.jar:na] at org.elasticsearch.cluster.service.InternalClusterService$UpdateTask.run(InternalClusterService.java:365) ~[elasticsearch-1.5.2.jar:na] at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.runAndClean(PrioritizedEsThreadPoolExecutor.java:188) [elasticsearch-1.5.2.jar:na] at org.elasticsearch.common.util.concurrent.PrioritizedEsThreadPoolExecutor$TieBreakingPrioritizedRunnable.run(PrioritizedEsThreadPoolExecutor.java:158) [elasticsearch-1.5.2.jar:na] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_77] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_77] at java.lang.Thread.run(Thread.java:745) [na:1.8.0_77] [ERROR] org.springframework.data.elasticsearch.repository.support.AbstractElasticsearchRepository - 加载Elasticsearch节点失败:org.elasticsearch.index.mapper.MapperParsingException: 找不到字段[nome]的分析器[autocomplete]
我无法确定问题的原因,不知道分析器是否无效或者Elasticsearch是否找到了autocomplete-analyser.json文件。该如何解决?