# How to GET an Entity from nested JSON Data using Query

**URL:** https://discuss.elastic.co/t/how-to-get-an-entity-from-nested-json-data-using-query/189818
**Category:** Kibana
**Created:** [July 10, 2019, 3:48pm UTC](https://discuss.elastic.co/t/how-to-get-an-entity-from-nested-json-data-using-query/189818 "2019-07-10T15:48:15Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![samyo](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@samyo](https://discuss.elastic.co/u/samyo)
#### Post date: [July 10, 2019, 3:48pm UTC](https://discuss.elastic.co/t/how-to-get-an-entity-from-nested-json-data-using-query/189818/1 "2019-07-10T15:48:15Z")

</div>

Hello folks ,  
i have this bellow JSON Data, and i want to write a Query , the Query is ,  
( **Give me all Entities where the "ai\_id" has the Value = 0** ).

the JSON Data ,

```auto
      {
        "_index": "try1",
        "_type": "_doc",
        "_id": "2",
        "_score": 1,
        "_source": {
          "target": {
            "br_id": 0,
            "an_id": 0,
            "ai_id": 0,
            "explanation": [
              "element 1",
              "element 2"
            ]
          },
          "process": {
            "an_id": 1311,
            "pa_name": "micha"
          },
          "text": "hello world"
        }
      },
      {
        "_index": "try1",
        "_type": "_doc",
        "_id": "1",
        "_score": 1,
        "_source": {
          "target": {
            "br_id": 0,
            "an_id": 1,
            "ai_id": 1,
            "explanation": [
              "element 3",
              "element 4"
            ]
          },
          "process": {
            "an_id": 1311,
            "pa_name": "luca"
          },
          "text": "the all People are good"
        }
      }
    ]
  }
}

```

I tried something like this , and did not work ,

```auto
GET try1\_search   
{
  "query":{
        { "match_all": { "ai_id": 0}}
  }
} 

```

and i tried this too , but did not work,

```auto
GET try1/_search
{
    "query": {
        "nested" : {
            "query" : {
                    "must" : [
                    { "match" : {"ai_id" : 0} }
                    ]
            }
        }
    }
}

```

Please any Suggestion i will be thankfull.

---

<div class="post-metadata">

### Author: ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)
#### Post date: [July 10, 2019, 6:28pm UTC](https://discuss.elastic.co/t/how-to-get-an-entity-from-nested-json-data-using-query/189818/2 "2019-07-10T18:28:52Z")

</div>

Use the following query. You need to prefix `ai_id` with `target` since the field is a key of target

```auto
{
  "query": {
    "match": {
      "target.ai_id": 0
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![samyo](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@samyo](https://discuss.elastic.co/u/samyo)
#### Post date: [July 11, 2019, 8:17am UTC](https://discuss.elastic.co/t/how-to-get-an-entity-from-nested-json-data-using-query/189818/3 "2019-07-11T08:17:51Z")

</div>

thx , it worked fine .  
Can you please tell how to write this Query using the RestClient API in low level Client?

thx in advance.

---

<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 8, 2019, 8:26am UTC](https://discuss.elastic.co/t/how-to-get-an-entity-from-nested-json-data-using-query/189818/4 "2019-08-08T08:26:54Z")

</div>

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