Elasticsearch with snowball analyzer returns word-only results

I am using a snowball analyzer in my string search string ... so

"query" : { "query_string" : { "query" : the-query-string-goes-here, "default_operator" : "AND", "analyzer" : "snowball" } } 

it really works, but it does something strange ... a search for “fighting” will return results for “battle”, but will ignore results for “battle”. A search for “crews” will return results for “crews,” but not “crews,” and a search for “crews” will also ignore results for “crews” ...

Does anyone know what is going on?

+6
source share
2 answers

A stem makes sense when you apply it both in index time and in query time. Now you apply it during the query to search for the source of the words that are part of the query. But I think that the index does not contain stems, since you did not use it when indexing. You are really looking in the _all field, since you did not specify the field name in your query, nor do you use the default_field (or fields ) attribute supported by query_string. The _all field is _all by default using StandardAnalyzer .

There are various solutions to this problem. I personally would decide the set of fields that you want to search for in your query, and apply them to them related to your mapping. After that, you do not need to specify the analyzer in the request, since the configured analyzer will be used for the field in which you are looking.

Let me know if the answer is clear enough.

+11
source

Thanks @javanna for pointing me in the right direction. I solved this by installing the analyzer for the _all field on snowball . See this document for more details.

I am using a Ruby bus pearl, and I have been able to specify the display in my model as follows:

 mapping(_all: { analyzer: 'snowball' }) do indexes :id, type: 'integer' indexes :description indexes :name, boost: 10 end 

I formatted my request exactly the same as in the original question.

+2
source

Source: https://habr.com/ru/post/924833/


All Articles