# Elasticsearch nested objects MUST bool filter

**URL:** <https://discuss.elastic.co/t/elasticsearch-nested-objects-must-bool-filter/135145>\
**Category:** Elasticsearch\
**Created:** [June 8, 2018, 11:57am UTC](https://discuss.elastic.co/t/elasticsearch-nested-objects-must-bool-filter/135145 "2018-06-08T11:57:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adam\_Krajcs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/adam_krajcs/32/45171_2.png) [@Adam\_Krajcs](https://discuss.elastic.co/u/Adam_Krajcs)\
**Post date:** [June 8, 2018, 11:57am UTC](https://discuss.elastic.co/t/elasticsearch-nested-objects-must-bool-filter/135145/1 "2018-06-08T11:57:21Z")

</div>

Hi,

I've the following nested index structure:  
"sector\_parametric": [  
{  
"sector": [  
"2"  
],  
"experience": 1.7,  
"adv\_business\_sector\_id": "637"  
},  
{  
"sector": [  
"1",  
"2",  
"10003"  
],  
"experience": 2.7,  
"adv\_business\_sector\_id": "642"  
}]

I want to show the documents with the sector value is 1 AND 2, BUT not necessarily in one nested object, so  
the following document would be perfect  
"sector\_parametric": [  
{  
"sector": [  
"1"  
],  
"experience": 1.7,  
"adv\_business\_sector\_id": "637"  
},  
{  
"sector": [  
"2",  
"10003"  
],  
"experience": 2.7,  
"adv\_business\_sector\_id": "642"  
}]

If I filter with the following query, there will be only documents where one nested sector object contains BOTH 1 AND 2:  
[query] =\> Array  
(  
[bool] =\> Array  
(  
[filter] =\> Array  
(  
[bool] =\> Array  
(  
[must] =\> Array  
(  
[0] =\> Array  
(  
[nested] =\> Array  
(  
[path] =\> sector\_parametric  
[query] =\> Array  
(  
[bool] =\> Array  
(  
[must] =\> Array  
(  
[0] =\> Array  
(  
[term] =\> Array  
(  
[sector\_parametric.sector] =\> 1  
)

```
                                                                                            )

                                                                                    )

                                                                            )

                                                                    )

                                                            )

                                                    )

                                                [1] => Array
                                                    (
                                                        [nested] => Array
                                                            (
                                                                [path] => sector_parametric
                                                                [query] => Array
                                                                    (
                                                                        [bool] => Array
                                                                            (
                                                                                [must] => Array
                                                                                    (
                                                                                        [0] => Array
                                                                                            (
                                                                                                [term] => Array
                                                                                                    (
                                                                                                        [sector_parametric.sector] => 2
                                                                                                    )

                                                                                            )

                                                                                    )

                                                                            )

                                                                    )

                                                            )

                                                    )

                                            )

                                    )

                            )

                    )

            )
```

---

<div class="post-metadata">

**Author:** ![topel](https://avatars.discourse-cdn.com/v4/letter/t/45deac/32.png) [@topel](https://discuss.elastic.co/u/topel)\
**Post date:** [June 8, 2018, 1:41pm UTC](https://discuss.elastic.co/t/elasticsearch-nested-objects-must-bool-filter/135145/2 "2018-06-08T13:41:01Z")

</div>

I dont have an answer to your question but would you be so kind to format your code with an indent of 4 spaces like the last part accidentally is so future onlookers can and understand it better?

---

<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, 2018, 1:41pm UTC](https://discuss.elastic.co/t/elasticsearch-nested-objects-must-bool-filter/135145/3 "2018-07-06T13:41:02Z")

</div>

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