Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elastic Search nested multimatch query

Tags:

So my problem is basically the same as described here, however it still remains unanswered on the group.

My mapping:

{     "abstract": {         "properties": {             "summary": {                 "type": "string"             }         }     },     "authors": {         "type": "nested",         "properties": {             "first_name": {                 "type": "string"             },             "last_name": {                  "type": "string"             }         }     } } 

And I would like to perform a full-text search on both of these fields, probably unequally weighted. The query that comes to my mind, but unfortunately doesn't work, would be this:

{     "query": {         "bool": {             "should": [{                 "multi_match": {                     "query": "higgs boson",                     "fields": ["abstract.summary^5", "author.last_name^2"]                 }             }]         }     } } 

I don't get any results from the authors field, because of its nested mapping. I also can't get rid of the nested property - I use it for aggregations. Any elegant idea how to solve it?

like image 455
stpk Avatar asked Aug 05 '15 10:08

stpk


People also ask

What is nested query in elastic search?

You can perform a nested query in Elasticsearch by using the nested parameter. A nested query will search the nested field objects and return the document's root parent if there's a matching object.

What is multi match query in Elasticsearch?

The multi_match query builds on the match query to allow multi-field queries: GET /_search { "query": { "multi_match" : { "query": "this is a test", "fields": [ "subject", "message" ] } } } The query string. The fields to be queried.

What is nested type in Elasticsearch?

The nested type is a specialised version of the object data type that allows arrays of objects to be indexed in a way that they can be queried independently of each other.

What is Multimatch?

Multi-Match® Multi-Match is a lotto-style game. For just $2.00, you get to play 18 numbers with four easy ways to match and win. When you play Multi-Match, for each game you play, you will be able to select your first line of six numbers or you can choose Quick Pick.


1 Answers

The only solution that I managed to work out, which is not handy nor elegant but somehow works is such query:

"query": {     "bool": {         "should": [             {                 "nested": {                     "path": "authors",                     "query": {                         "multi_match": {                             "query": "higgs",                             "fields": ["last_name^2"]                         }                     }                 }              },             {                 "multi_match": {                     "query": "higgs",                     "fields": ["abstract.summary^5"]                 }             }         ]     } } 

I'm also not sure if the boosting will work as expected, providing it's set in different queries. Any suggestions appreciated.

like image 79
stpk Avatar answered Sep 18 '22 11:09

stpk