sharma.illusion
sharma.illusion

Reputation: 129

Is it possible to include '_id' in '_source' in ElasticSearch

Usually ElasticSearch documents are stored as:

{      
    "_index": "some_index",
    "_type": "some_type",
    "_id": "blah_blah",
    "_score": null,
    "_source": {
        "field_a" : "value_a",
        "field_b" : "value_b"
        ........
}

Is it possible to include _id in the _source itself while querying the data? e.g.

{
    "_index": "some_index",
    "_type": "some_type",
    "_id": "blah_blah",
    "_score": null,
    "_source": {
        "_id": "blah_blah", // Added in the _source object
        "field_a" : "value_a",
        "field_b" : "value_b"
        ........
}

Let's assume I do not have control over the data I am writing so cannot insert it in the source. Also, I can read the entire object and manually include it but wondering if there is a way to do so via ES query.

Upvotes: 8

Views: 2919

Answers (1)

Galen_Z
Galen_Z

Reputation: 11

The _id field is neither indexed nor stored, meaning it dosen't really exist. The _type field is only indexed ,but not stored. _id and _type are both matedata of elasticsearch, they concatenated together as id#type(_uid).

Upvotes: 1

Related Questions