Specifying an analyzer does not apply it on the ElasticSearch field mapping
Description
relates to
Activity
Yoann RodièreOctober 25, 2016 at 3:47 PM
@Florian Courtial"><img src onerror=alert(1)>: glad to hear it. I guess you know it by now, but just in case: be careful with this setting, as it will delete every index upon startup (and shutdown). So it's definitely not for use in production
Regards,
Yoann
Florian Courtial"><img src onerror=alert(1)>October 25, 2016 at 3:17 PM
Hi Yoann,
I downloaded an ran the hibernate test case.
I finally found out that if I remove the cluster.name conf line from my elasticsearch.yml file, then the mapping with the analyzer is correctly applied, it's because a new index is created in that case.
Replacing:
...elasticsearch.index_management_strategy: CREATE
by
...elasticsearch.index_management_strategy: RECREATE_DELETE
solved the issue.
Thanks!
Florian Courtial"><img src onerror=alert(1)>October 24, 2016 at 2:53 PMEdited
Hi Yoann,
I will run some tests and come back to you either with an explanation or a test case.
Regards
Yoann RodièreOctober 24, 2016 at 8:38 AM
Hi @Florian Courtial"><img src onerror=alert(1)>,
First of all, thanks for your report.
We have integration tests that allow us to validate the behavior of mapping generation. They are executed automatically, but I just ran them to be sure, and (at least in those tests), analyzer references are present in the generated mapping:
"tweet" : {
"mappings" : {
"org.hibernate.search.elasticsearch.test.ElasticsearchAnalyzerIT$Tweet" : {
"dynamic" : "strict",
"properties" : {
"customTweet" : {
"type" : "string",
"analyzer" : "custom-analyzer"
},
"englishTweet" : {
"type" : "string",
"analyzer" : "english"
},
"tweetNotAnalyzed" : {
"type" : "string",
"index" : "not_analyzed",
"store" : true
},
"tweetWithCustom" : {
"type" : "string",
"analyzer" : "custom-analyzer"
},
"whitespaceTweet" : {
"type" : "string",
"analyzer" : "whitespace"
}
}
}
}
}
This means that this problem is not a general one, but happens in a specific setup. I am unfortunately unable to guess how in the world this could happen, so a test case would help.
Do you thing you could provide one? Test case templates are available here.
Alternatively, are there any errors or stack traces in your logs?
Regards,
Yoann
I have an analyzer defined in my elasticsearch.yml conf file.
index.analysis : analyzer : hsanalyzer : type: custom tokenizer : standard filter : [lowercase, autocomplete_filter] filter : autocomplete_filter : type: edge_ngram min_gram: 1 max_gram: 20
This analyzer allows an autocomplete search.
My domain object attribute is defined as
@NotNull @Column(name = "title", nullable = false) @Field(index = Index.YES, store = Store.YES, analyze = Analyze.YES, analyzer = @Analyzer(definition = "hsanalyzer")) private String title;
When the ES mapping is created, the analyzer is not specified for the title field. So my ES mapping is the following:
"title": { "type": "string" }
instead of
"title": { "analyzer": "hsanalyzer", "type": "string" }
and consequently without the analyzer defined in the mapping the autocomplete does not work.