Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 216
sharma.illusion Avatar asked Jun 04 '15 22:06

sharma.illusion


People also ask

Can Id be a string in Elasticsearch?

The _id (metadata _id, that is) is a string value. created). You have complete freedom to set it to any string value you wish. use it quite effectively in this way.

How does Elasticsearch generate ID?

The ID is now generated with a time based element, but the byte re-ordering causes it not to be sortable by time. You could write a script field using Painless that would put it back in sortable order and then use that.

What kind of data can be stored in Elasticsearch?

Instead of storing information as rows of columnar data, Elasticsearch stores complex data structures that have been serialized as JSON documents. When you have multiple Elasticsearch nodes in a cluster, stored documents are distributed across the cluster and can be accessed immediately from any node.

How do I find Elasticsearch document ID?

To get the ID of a document, simply use the _id field in the search query. For example, if you want to find the document with the ID "12345", you would use the following query: _id:12345. This would return the document with the ID "12345".


1 Answers

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).

like image 75
Galen_Z Avatar answered Oct 21 '22 23:10

Galen_Z