Nested search with multiple must query not working

I have the following mapping within my elastic Index:

"equipment": {
                "type": "nested",
                "properties": {
                    "equipment_category": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "equipment_name": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                 }
            }

I have now the following problem:

Using the following query with the SAME "equipment_name" like "Climatic" keyword will return
all results containing the keyword "Climatic".

But using different keywords, like "Climatic" and "Inverter", will show no results at all:

GET _search
    { 
       "nested":{ 
          "path":"equipment",
          "query":{ 
             "bool":{ 
                "must":[ 
                   { 
                      "match":{ 
                         "equipment.equipment_name":"Climatic"
                      }
                   },
                   { 
                      "match":{ 
                         "equipment.equipment_name":"Inverter"
                      }
                   }
                ]
             }
          }
       }
    }

What am I doing wrong?

can you include a fully reproducible example that contains documents with only a single equipment name field, that should match, so that others can reproduce and test?

Thanks!

1 Like

So here is an example, i hope it clearifys my problem:

{
                "_index": "ssy_yachtall",
                "_type": "_doc",
                "_id": "26042020-07-25T00:00:00.000Z21.0Bareboat",
                "_score": 1.0,
                "_source": {
                    "cabins": 2.0,
                    "motor": "29 hp",
                    "waterline": "10.72 m",
                    "equipment": [
                        {
                            "id_equipment": 15,
                            "id_ssy_yacht": 2604,
                            "bs_key": "mmk",
                            "filter": true,
                            "equipment_category": "Technik",
                            "equipment_name": "Climatic"
                        },
                    ],
                    "hafen_ziel": 154,
                    "transitlog": 0,
                }
},
 {
                "_index": "ssy_yachtall",
                "_type": "_doc",
                "_id": "13902020-02-08T00:00:00.000Z14.0Bareboat",
                "_score": 1.0,
                "_source": {
                    
                    "cabins": 1.0,
                    "motor": "Yanmar 2YM15 14HP",
                    "waterline": "7.63 m",
                    "equipment": [
                        {
                            "id_equipment": 28,
                            "id_ssy_yacht": 1390,
                            "bs_key": "mmk",
                            "filter": true,
                            "equipment_category": "Technik",
                            "equipment_name": "Inverter"
                        }
                    ],
                    "hafen_ziel": 11,
                    "transitlog": 0,
                }
            },

your query is an AND query, that needs to contain Climatic and Inverter in the same nested document. Hwoever your sample document does not satisfy that condition. Try using to queries in a should clause, that act as an OR unless you add filter/must/must_not clauses to the bool query.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.