# How to filter array of nested objects that must have all terms apllied

**URL:** <https://discuss.elastic.co/t/how-to-filter-array-of-nested-objects-that-must-have-all-terms-apllied/32342>\
**Category:** Elasticsearch\
**Created:** [October 16, 2015, 10:04am UTC](https://discuss.elastic.co/t/how-to-filter-array-of-nested-objects-that-must-have-all-terms-apllied/32342 "2015-10-16T10:04:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alvin\_Tanjaya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alvin_tanjaya/32/12317_2.png) [@Alvin\_Tanjaya](https://discuss.elastic.co/u/Alvin_Tanjaya)\
**Post date:** [October 16, 2015, 10:04am UTC](https://discuss.elastic.co/t/how-to-filter-array-of-nested-objects-that-must-have-all-terms-apllied/32342/1 "2015-10-16T10:04:01Z")

</div>

Hi guys, I really have difficulties in understanding how the query DSL works, I have a object like this :

```
{
    "name": "Asus Zenphone",
    "brand": "Asus",
    "items": [
      {
        "price": 2000000,
        "options": [
          {
            "name": "Color",
            "value": "Red"
          },
          {
            "name": "Memory Capacity",
            "value": "16GB"
          }
        ]
      },
      {
        "price": 2000000,
        "options": [
          {
            "name": "Color",
            "value": "Black"
          },
          {
            "name": "Memory Capacity",
            "value": "16GB"
          }
        ]
      },
      {
        "price": 2000000,
        "options": [
          {
            "name": "Color",
            "value": "White"
          },
          {
            "name": "Memory Capacity",
            "value": "16GB"
          }
        ]
      },
      {
        "price": 4000000,
        "options": [
          {
            "name": "Color",
            "value": "Black"
          },
          {
            "name": "Memory Capacity",
            "value": "32GB"
          }
        ]
      },
      {
        "price": 4000000,
        "options": [
          {
            "name": "Color",
            "value": "White"
          },
          {
            "name": "Memory Capacity",
            "value": "32GB"
          }
        ]
      }
    ]
  }

```

How could I get a result empty if I find product with Color Red and Memory Capacity 32GB but get result 1 product if i find Color Red and Memory Capacity 16GB?

I've tried using this query but it give me empty result for both :

```
{
  "query": {
    "filtered": {
      "filter": {
        "and": [
          {
            "terms": {
              "brand": [
                "Asus",
                "Apple"
              ]
            }
          },
          {
            "nested": {
              "path": "items.options",
              "filter": {
                "bool": {
                  "must": [
                    {
                      "bool": {
                        "must": [
                          {
                            "term": {
                              "items.options.name": "Memory Capacity"
                            }
                          },
                          {
                            "terms": {
                              "items.options.value": [
                                "32GB"
                              ]
                            }
                          }
                        ]
                      }
                    },
                    {
                      "bool": {
                        "must": [
                          {
                            "term": {
                              "items.options.name": "Color"
                            }
                          },
                          {
                            "terms": {
                              "items.options.value": [
                                "Red"
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              }
            }
          }
        ]
      }
    }
  }
}
```

---

<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:** [July 5, 2017, 11:44pm UTC](https://discuss.elastic.co/t/how-to-filter-array-of-nested-objects-that-must-have-all-terms-apllied/32342/2 "2017-07-05T23:44:24Z")

</div>


