# Query nested object array with Java API

**URL:** <https://discuss.elastic.co/t/query-nested-object-array-with-java-api/38568>\
**Category:** Elasticsearch\
**Created:** [January 7, 2016, 5:25am UTC](https://discuss.elastic.co/t/query-nested-object-array-with-java-api/38568 "2016-01-07T05:25:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![guiltyxsin](https://avatars.discourse-cdn.com/v4/letter/g/6bbea6/32.png) [@guiltyxsin](https://discuss.elastic.co/u/guiltyxsin)\
**Post date:** [January 7, 2016, 5:25am UTC](https://discuss.elastic.co/t/query-nested-object-array-with-java-api/38568/1 "2016-01-07T05:25:18Z")

</div>

Hi,

I am a noob and I am trying to use Java API to query a nested object array. Here's the mapping:

```
mappings": {
      "tag": {
        "properties": {
          "entities": {
            "properties": {
              "type": {
                "type": "string",
                "index": "not_analyzed",
                "store": true
              },
              "value": {
                "type": "string",
                "index": "not_analyzed",
                "store": true
              }
            }
          },
          "tag_id": {
            "type": "string",
            "index": "not_analyzed",
            "store": true
          }
        }
      }
    }

```

I am trying to query with the following:

> client().prepareSearch(INDEX)  
> .setTypes(INDEX\_TYPE)  
> .setFetchSource(false)  
> .setVersion(false)  
> .setQuery(query)  
> .setSize(10)  
> .addField(TAG\_ID)  
> .addFieldDataField(ENTITIES)  
> .get()  
> .getHits();

I can see the tag ID and entity field but there's nothing under the entity data field where there supposed to be an array of entities.

But from sense I can see:

```
      "tag_id": "0276f681-c417-41c4-90d3-d91292e0a5c0",
      "entities": [
        {
          "type": "url",
          "value": "http://www.abc.com"
        },
        {
          "type": "url",
          "value": "http://www.xyz.com"
        }

```

What did I do wrong in Java?

Thank you.

Regards,  
Andy

---

<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:26pm UTC](https://discuss.elastic.co/t/query-nested-object-array-with-java-api/38568/2 "2017-07-05T23:26:32Z")

</div>


