How to GET an Entity from nested JSON Data using Query

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 ,

      {
        "_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 ,

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

and i tried this too , but did not work,

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

Please any Suggestion i will be thankfull.

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

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

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

thx in advance.

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