I'm trying to perform a multi match query on some data I have structured as nested types. When I search for something like "gadget plushy" I get no matches for a document with two nested fields "gadget" and "plushy". The following is an example what's not working for me
PUT /testing/_doc/1
{
"items": [{"name": "gadget"}, {"name": "plushy"}]
}
PUT /testing/_doc/2
{
"items": [{"name": "gadget"}]
}
PUT /testing/_doc/3
{
"items": [ {"name": "plushy"}]
}
And finally search for both gadget and plushy, this gives zero hits for me. Searching for either gadget or plushy in the same query yields two results each though.
I'm expecting this multi match query for "gadget plushy" should return the first document since the first nested item is named gadget and the second nested item is named plushy. Am I not understanding how this multi match queries should work for nested types or did I do something wrong?
Hello @RabBit_BR and thank you for taking your time to answer me.
If I do OR I will get 3 results, I expect to only get a hit when at least one field includes plushy and one field includes gadget. This works for non nested fields. The following code sets up something similar like my original post but without nested fields. Running the last query yields exactly one result, document 1. This is what I expect for nested fields as well.
## Multi match without nested fields
PUT /testing
{
"mappings": {
"properties": {
"item1": {"type": "text"},
"item2": {"type": "text"}
}
}
}
PUT /testing/_doc/1
{
"item1": "gadget",
"item2": "plushy"
}
PUT /testing/_doc/2
{
"item1": "gadget",
"item2": "nothing"
}
PUT /testing/_doc/3
{
"item1": "plushy",
"item2": "nothing"
}
POST /testing/_search
{
"query": {
"multi_match": {
"fields": [
"item1", "item2"
],
"operator": "and",
"query": "gadget plushy",
"type": "cross_fields"
}
}
}
Normally you would use nested fields only when you want the isolation you’re experiencing.
It’s designed for criteria that needs to test properties of nested objects in isolation.
Without nested fields you get the “cross matching” style that doesn’t care which contained objects provide a match.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.