Find out which fields match multiple matches

I use a typical multi-user query in three fields: name, city, state. The multiple-match query also uses an evaluation of the Java script function. Is there any way to find out in the script account which fields match my query with multiple matches? If not, is there a way to figure this out from the SearchResponse object?

I'm on Elasticsearch 1.2.1 right now, but I can easily upgrade if necessary.

+5
source share
2 answers

I don't think you can do this directly with just a few matches, but if you add highlighting, you should get an answer showing which fields were matched:

http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/highlighting-intro.html

In the example from this page:

GET /megacorp/employee/_search { "query" : { "match_phrase" : { "about" : "rock climbing" } }, "highlight": { "fields" : { "about" : {} } } } 

you changed match_phrase to multi_match and added a list of fields:

  GET /megacorp/employee/_search { "query" : { "multi_match" : { "query" : "rock climbing", "fields": ["about", "otherfield"] } }, "highlight": { "fields" : { "about" : {}, "otherfield": {} } } } 

and this should help you highlight an answer that includes highlighting around the corresponding text and the field that has been matched.

+5
source

There is one more exact way to find out which field is matched in the query.

Because highlighting is the process of highlighting after publication, it is inaccurate because of how it was done.

Just use a named query to do this instead of multitasking

such as

  { "multi_match" : { "query" : "query phrase here", "fields" : [ "name", "tag", "categorys" ], "operator" : "AND" } 

translate it into a bool request named

  "should": [ { "match": { "name": { "query": "query phrase here", "_name":"name_field" } } },{ "match": { "tag":{ "query": "query phrase here", "_name":"tag_field" } } },{ "match": { "categorys":{ "query": "query phrase here", "_name":"cat_field" } } } ] 

it will return a result like this

  { "_index": "indexName", "_type": "type", "_id": "id", "_score": 0.27836448, "matched_queries": [ "tag_field" ] }, { "_index": "indexName", "_type": "type", "_id": "id", "_score": 0.27836448, "matched_queries": [ "name_field", "tag_field" ] } 
+2
source

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


All Articles