# Combine SHOULD/MUST condition to filter nested data

**URL:** <https://discuss.elastic.co/t/combine-should-must-condition-to-filter-nested-data/1830>\
**Category:** Elasticsearch\
**Created:** [June 3, 2015, 1:24pm UTC](https://discuss.elastic.co/t/combine-should-must-condition-to-filter-nested-data/1830 "2015-06-03T13:24:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christian\_Rutgers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_rutgers/32/500_2.png) [@Christian\_Rutgers](https://discuss.elastic.co/u/Christian_Rutgers)\
**Post date:** [June 3, 2015, 1:24pm UTC](https://discuss.elastic.co/t/combine-should-must-condition-to-filter-nested-data/1830/1 "2015-06-03T13:24:29Z")

</div>

Hello,

after some hours without a reliable solution but headaches I'll ask for some advice.

I have a data set like the one below. Id like to get the "articles" who match the condition of:

> product\_taxonomy.product\_taxonomy\_id = (10 OR 20) AND (31 OR 33)

Expected results are the articles with article\_id a123, b456 and C789.  
I tried a lot, most with nested bool query with nested "must" with two "should's" but I struggle to combine the two OR parts with an AND.

```
{ 
    "article_id" : "a123",
    "product_taxonomy": [
      { "product_taxonomy_id": 10 },
      { "product_taxonomy_id": 31 },
      { "product_taxonomy_id": 33 }
    ]
},
{ 
    "article_id" : "b456",
    "product_taxonomy": [
      { "product_taxonomy_id": 10 },
      { "product_taxonomy_id": 20 },
      { "product_taxonomy_id": 31 },
      { "product_taxonomy_id": 32 }
    ]
},
{ 
    "article_id" : "c789",
    "product_taxonomy": [
      { "product_taxonomy_id": 10 },
      { "product_taxonomy_id": 21 },
      { "product_taxonomy_id": 31 },
      { "product_taxonomy_id": 34 }
    ]
},
{ 
    "article_id" : "x987",
    "product_taxonomy": [
      { "product_taxonomy_id": 10 },
      { "product_taxonomy_id": 20 },
      { "product_taxonomy_id": 32 },
      { "product_taxonomy_id": 34 }
    ]
},
{ 
    "article_id" : "y654",
    "product_taxonomy": [
      { "product_taxonomy_id": 11 },
      { "product_taxonomy_id": 21 },
      { "product_taxonomy_id": 31 },
      { "product_taxonomy_id": 33 }
    ]
}

```

May someone please give me a brief idea on how this might be solved?

Thanks in advance,  
Christian

---

<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 6, 2017, 12:09am UTC](https://discuss.elastic.co/t/combine-should-must-condition-to-filter-nested-data/1830/2 "2017-07-06T00:09:54Z")

</div>


