# Querying 2 nested objects in an document?

**URL:** <https://discuss.elastic.co/t/querying-2-nested-objects-in-an-document/91975>\
**Category:** Elasticsearch\
**Created:** [July 5, 2017, 6:59pm UTC](https://discuss.elastic.co/t/querying-2-nested-objects-in-an-document/91975 "2017-07-05T18:59:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaushah](https://avatars.discourse-cdn.com/v4/letter/k/dfb087/32.png) [@kaushah](https://discuss.elastic.co/u/kaushah)\
**Post date:** [July 5, 2017, 6:59pm UTC](https://discuss.elastic.co/t/querying-2-nested-objects-in-an-document/91975/1 "2017-07-05T18:59:30Z")

</div>

I have a nested document as follows:

```
{
"Tags" : {
     "key1" : "value1",
     "key2" : "value2",
     "key3" : "value3"
             },
"NameArray" : [ 
     {
     "Name1" : ["Value1", "Value2" , "Value3"],
     "TimeStamp" : "Value"
     },
     {
     "Name2" : ["Value1", "Value2" , "Value3"],
     "TimeStamp" : "Value"
     }
     ]
}

```

where Tag and NameArray are of type nested.

How do I query for a particular name for a given timestamp with all the Tag values given?

I tried this:

```
GET index1/type1/_search
{
  "query" : {
    "nested" : {
      "path" : [{"NameArray"},{"Tags"}],
      "query" : {
        "bool" : {
          "must" : [{"match" : {"Tags.key1.keyword": "a"}},
                    {"match" : {"Tags.key2.keyword": "b"}},
                    {"match" : {"Tags.key3.keyword": "c"}}, 
                    {"range" : {"NameArray.TimeStamp" : {"gte":"2010-07-16T10:24:15.795Z","lte":"2015-07-16T10:24:15.795Z"}}}]
        }
      }
    }
   
  }
}

```

This doesn't work. Where am I going wrong?

---

<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:** [August 2, 2017, 6:59pm UTC](https://discuss.elastic.co/t/querying-2-nested-objects-in-an-document/91975/2 "2017-08-02T18:59:39Z")

</div>

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