Skip to content

Able to have different _id value than the one in the _source #5488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Diolor opened this issue Mar 21, 2014 · 3 comments
Closed

Able to have different _id value than the one in the _source #5488

Diolor opened this issue Mar 21, 2014 · 3 comments

Comments

@Diolor
Copy link

Diolor commented Mar 21, 2014

I have edited this issue since the previous was wrong.

Is it possible to have a different _id value in ES than the one inside the _source? The following is a bulk action:

action = {
    '_type': 't',
    '_id': '52cb45cec36b4442751728f5',
    '_source': {
        u'city': u'Toronto',
        u'name': u'PostBeyond',
        u'_id': {
            '$oid': '52cb45cdc36b4442751728f4'
        },
        u'events': {
            u'title': u'ExtremeCachingwithPHP',
            u'event_id': {
                '$oid': '52cb45cec36b4442751728f5'
            },
            u'start_date': u'2014-01-08T00:00:00+00:00'
        }
    },
    '_index': 'i'
}

If we give manually the _id ES not to search inside the source document.

It would have been useful to cooperate with mongodb or generally if we want to have in the _source the field _id.

Relevant documentation: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-id-field.html#mapping-id-field

@Diolor Diolor changed the title Sorting based on inner children Able to have different _id value than the one in the _source Mar 24, 2014
@clintongormley
Copy link
Contributor

I'm sorry but I don't understand your question at all. Could you try explaining a bit more?

@Diolor
Copy link
Author

Diolor commented Mar 26, 2014

Yes; sorry for the badly written issue.

Elasticsearch always searches for an _id inside the document which is going to be indexed.
In MongoDB, each document has an _id field which is in a {'_id': { '$oid': '52cb45cdc36b4442751728f4' } } format. e.g. the document:

{'_id': { '$oid': '52cb45cdc36b4442751728f4' },'testkey':'testvalue'}

I am working on adding elasticsearch as searching layer so I cannot keep the same structure both in MongoDB and ES.

I either have to rename _id inside the source to id (or something else) or set _id to a {'_id': '52cb45cdc36b4442751728f4' } format happily to be handled by ES.

Generally if I could disable ES searching inside the document for an _id field (at least in bulk feed where you can set/give the _id on the same level with _source) I would be able use the _id inside the _source without any limitations of its structure.

However this is a minor issue since can be solved in the webservice or end client.

@clintongormley
Copy link
Contributor

On v1.x, the {"_id": { "$oid"...} is ignored because it is an object rather than a string, so you should be fine when you upgrade. However, I think there is still an issue here when you use documents like { "_id": "xxx"}, so I've opened #5558.

What you could do with your current version is to map the _id field to use _id.$oid explicitly:

PUT /myindex/
{
    "mappings": {
        "mytype": {
            "_id": {
                "path": "_id.$oid"
            }
        }
    }
}

I'll close this in favour of #5558

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants