# Search in object array with multiple conditions

**URL:** <https://discuss.elastic.co/t/search-in-object-array-with-multiple-conditions/169440>\
**Category:** Elasticsearch\
**Created:** [February 21, 2019, 2:59pm UTC](https://discuss.elastic.co/t/search-in-object-array-with-multiple-conditions/169440 "2019-02-21T14:59:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trino](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@Trino](https://discuss.elastic.co/u/Trino)\
**Post date:** [February 21, 2019, 2:59pm UTC](https://discuss.elastic.co/t/search-in-object-array-with-multiple-conditions/169440/1 "2019-02-21T14:59:48Z")

</div>

Hi,

I hope you can help me to find the solution, my problem is:

I have a list of documents indexed in my index like this:

```
{
 "title" : "document 1",
 "status" 2,
 "documentParts" : [{ "partTitle": "part 1",
					  "typePart" : 1,
					  "statusPart" : 2},
					{ "partTitle": "part 2",
					  "typePart" : 2,
					  "statusPart" : 1}]
 

},
{
 "title" : "document 2",
 "status" 2,
 "documentParts" : [{ "partTitle": "part 2",
					  "typePart" : 2,
					  "statusPart" : 2}]
 

},
{
 "title" : "document 3",
 "status" 2,
 "documentParts" : [{ "partTitle": "part 1",
					  "typePart" : 1,
					  "statusPart" : 1},
					{ "partTitle": "part 2",
					  "typePart" : 2,
					  "statusPart" : 2}]
 

},
{
 "title" : "document 4",
 "status" 2,
 "documentParts" : [{ "partTitle": "part 1",
					  "typePart" : 1,
					  "statusPart" : 1},
					{ "partTitle": "part 2",
					  "typePart" : 2,
					  "statusPart" : 1}]

}

```

I want the documents that have the "documentParts" with "typePart = 1" and "statusPart = 1" In te same item of "documentParts" array.  
The wished documents are "document 3" and "document 4" but when I make the following I obtain the "document 1", "document 3", "document 4" because the query search in any element of array, not in the same array item.

Query:

```
{
  "from": 0,
  "size": 10,  
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "status": {
              "value": 2
            }
          }
        },
        {
          "terms": {
            "documentParts.typePart": [1],
            "_name": "documentPartFilter"
          }
        },
        {
          "terms": {
            "documentParts.statusPart": [1],
            "_name": "documentPartStatusFilter"
          }
        }
      ]
    }
  }
}

```

What is the way to search in the same array item?

Thanks for the help, if you need any clarification, tell me.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 21, 2019, 3:10pm UTC](https://discuss.elastic.co/t/search-in-object-array-with-multiple-conditions/169440/2 "2019-02-21T15:10:57Z")

</div>

Have a look at [https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html)

---

<div class="post-metadata">

**Author:** ![Trino](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@Trino](https://discuss.elastic.co/u/Trino)\
**Post date:** [February 21, 2019, 3:27pm UTC](https://discuss.elastic.co/t/search-in-object-array-with-multiple-conditions/169440/3 "2019-02-21T15:27:31Z")

</div>

Thanks.

---

<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:** [March 21, 2019, 3:27pm UTC](https://discuss.elastic.co/t/search-in-object-array-with-multiple-conditions/169440/4 "2019-03-21T15:27:33Z")

</div>

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