elasticsearch query for finding id in fields in json file

Viewed 222

I have a json file that I indexed on elasticsearch and I need a query to retrieve "_id_osm". can you help me plz. and this is one line of my json file:

{
  "index": {
    "_index": "pariss",
    "_type": "sig",
    "_id": 1
  }
}{
  "fields": {
    "_id_osm": 416747747,
    "_categorie": "",
    "_name": [
      ""
    ],
    "_location": [
      36.1941834,
      5.3595221
    ]
  }
}
1 Answers

Based on the comments in the answer updated the answer,

If you have store true in your mapping for _id_osm then you can use below query to fetch the field value.

{
  "stored_fields" : ["_id_osm"],
  "query": {
    "match": {
      "_id": 1
    }
  }
}

Above call returns below response and you can notice the fields section in the response which contains the field name and value.

 "hits": [
            {
                "_index": "intqu",
                "_type": "_doc",
                "_id": "1",
                "_score": 1.0,
                "fields": {
                    "_id_osm": [
                        416747747
                    ]
                }
            }
        ]

If you don't have store true which is default, then use _source filtering to get the data.

{
  "_source": [ "_id_osm" ],
  "query": {
    "match": {
      "_id": 1
    }
  }
}

which returns below response, you can see _source has the data.

 "hits": [
            {
                "_index": "intqu",
                "_type": "_doc",
                "_id": "1",
                "_score": 1.0,
                "_source": {
                    "_id_osm": 416747747
                }
            }
        ]
Related