# Nested search with multiple must query not working

**URL:** <https://discuss.elastic.co/t/nested-search-with-multiple-must-query-not-working/219990>\
**Category:** Elasticsearch\
**Created:** [February 19, 2020, 2:43pm UTC](https://discuss.elastic.co/t/nested-search-with-multiple-must-query-not-working/219990 "2020-02-19T14:43:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dreamfish](https://avatars.discourse-cdn.com/v4/letter/d/977dab/32.png) [@dreamfish](https://discuss.elastic.co/u/dreamfish)\
**Post date:** [February 19, 2020, 2:43pm UTC](https://discuss.elastic.co/t/nested-search-with-multiple-must-query-not-working/219990/1 "2020-02-19T14:43:22Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 19, 2020, 3:01pm UTC](https://discuss.elastic.co/t/nested-search-with-multiple-must-query-not-working/219990/2 "2020-02-19T15:01:30Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![dreamfish](https://avatars.discourse-cdn.com/v4/letter/d/977dab/32.png) [@dreamfish](https://discuss.elastic.co/u/dreamfish)\
**Post date:** [February 25, 2020, 4:41pm UTC](https://discuss.elastic.co/t/nested-search-with-multiple-must-query-not-working/219990/3 "2020-02-25T16:41:38Z")

</div>

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,
                }
            },
```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [March 12, 2020, 10:19am UTC](https://discuss.elastic.co/t/nested-search-with-multiple-must-query-not-working/219990/4 "2020-03-12T10:19:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 9, 2020, 10:19am UTC](https://discuss.elastic.co/t/nested-search-with-multiple-must-query-not-working/219990/5 "2020-04-09T10:19:47Z")

</div>

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