I'm trying to use ElasticSearch in my application for full text search and at this time I'm trying use autocomplete analyser:
{
"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"
]
}
}
}
}
}
As my application was constructed with Spring, I've decided use Spring-data-elasticsearch and mapped my entity this way:
@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;
}
However, elasticsearch isn't loading the custom analyser:
[DEBUG] org.elasticsearch.action.admin.indices.mapping.put - [Magus] failed to put mappings on indices [[estabelecimento]], type [esestabelecimento] org.elasticsearch.index.mapper.MapperParsingException: Analyzer [autocomplete] not found for field [nome] 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 - failed to load elasticsearch nodes : org.elasticsearch.index.mapper.MapperParsingException: Analyzer [autocomplete] not found for field [nome]
I can't identify the cause of the problem, I don't know if the analyser is invalid or elasticsearch even found the autocomplete-analyser.json file. How can I solve this?
I guess you need to remove the field "settings":
from json file and put only the content .
Instead of using :
{
"settings": {
....
}
}
Just use :
{
"index": {
"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"
]
}
}
}
}
}
Hope it helps you..
Solved
After some research I've discovered the problem was caused by this declaration:
@Bean
public ElasticsearchOperations elasticsearchTemplate(Client client) {
return new ElasticsearchTemplate(client, new CustomEntityMapper());
}
I removed this declaration and it began get the configuration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With