How should I query Elastic Search, given my mapping and use of keywords?

I have a very simple mapping that looks like this (I simplified the example a bit):

{ "location" : { "properties": { "name": { "type": "string", "boost": 2.0, "analyzer": "snowball" }, "description": { "type": "string", "analyzer": "snowball" } } } } 

Now I index many locations using some random values ​​that are based on real English words.

I would like to be able to search for locations that match any of the specified keywords in the name or in the description field (the name is more important, therefore, the promotion I gave). I tried several different queries and they do not return any results.

 { "fields" : ["name", "description"], "query" : { "terms" : { "name" : ["savage"], "description" : ["savage"] }, "from" : 0, "size" : 500 } } 

Given that there are places in which the word "wild" in the description, it should get me some results (the savage is the core of the savage). It gives 0 results using the above query. I used curl to query ES:

 curl -XGET -d @query.json http://localhost:9200/myindex/locations/_search 

If I use the query string instead:

 curl -XGET http://localhost:9200/fieldtripfinder/locations/_search?q=description:savage 

In fact, I get one result (of course, now it will only look for the description field).

Basically, I am looking for a query that will perform an OR type search using several keywords and compare them with the values ​​in both the name and description field.

+6
source share
1 answer

Snowball flows into the savagah "savage", so the term "savage" did not give any results. However, when you specify the "savage" at the URL, its analysis is analyzed and you get the results. Depending on your intention, you can use the correct stem ("savag") or analyze your terms using the match query instead of the terms:

 { "fields" : ["name", "description"], "query" : { "bool" : { "should" : [ {"match" : {"name" : "savage"}}, {"match" : {"description" : "savage"}} ] }, "from" : 0, "size" : 500 } } 
+6
source

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


All Articles