Elastic Search nested multimatch query
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.
Changing your mapping to the following one which uses include_in_root: true
will allow you to use the query you original wrote:
{ "abstract": { "properties": { "summary": { "type": "string" } } }, "authors": { "type": "nested", "include_in_root": true, "properties": { "first_name": { "type": "string" }, "last_name": { "type": "string" } } }}
You may want to index inner objects both as nested fields and as flattened object fields. This can be achieved by setting include_in_parent to true. - Link
Note: include_in_root
may be deprecated in future versions of elasticsearch in favor of copy_to
.