-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
If _id field is an object, no error is thrown but doc is "unsearchable" #3517
Comments
An exception is thrown if the provided id does not match the content id, but only if the content id is a string field. If the content id is a complex object, no exception is thrown but the document is indexed anyway, leading to problems with search later. This fix adds an additional check for _id fields that are objects and throws an exception if one is encountered Fixes elastic#3517
…xed_json` method Default Mongoid serialization keeps the `_id` property in the JSON as "BSON Object", which breaks Elasticsearch. See: * elastic/elasticsearch#3517 * rails-api/active_model_serializers#354 (comment)
…xed_json` method Default Mongoid serialization keeps the `_id` property in the JSON as "BSON Object", which breaks Elasticsearch. See: * elastic/elasticsearch#3517 * rails-api/active_model_serializers#354 (comment)
It's a little bit more fun than that, even: you actually get partial indexing!
Now search on the field before the _id:
There you go.
And you get nothing. |
I am affected by this behavior too, monogo output the field like this
actually I did not care about the "_id" field, but I care about the "@timestamp" field which is silently not indexed. Here an example that shows the behavior: |
In 2.0, the timestamp field would now be indexed correctly, as would |
The ability to specify _id within a document has already been removed for 2.0+ indexes. |
@rjernst you removed the ability to specify the main doc _id in the body, but if the body contains an What I'm asking is: should we just ignore the fact that this field is not accessible (as we do in master today) or should we actually throw an exception? I'm leaning towards ignoring, as users don't always have control over the docs they receive. |
I would be in favor of throwing an exception. This would only be for 2.0+ indexes, and it is really just field name validation (disallowing fields colliding with meta fields). The mechanism would be the same, a user would not be able to explicitly add a field |
@rjernst it's a tricky one. eg mongo adds |
IMO, yes. |
With #8871, I don't think that would work, because _id is both a field mapper (the real meta field), and an object mapper. |
@rjernst yep, makes sense |
Closed by #14003 |
…xed_json` method Default Mongoid serialization keeps the `_id` property in the JSON as "BSON Object", which breaks Elasticsearch. See: * elastic/elasticsearch#3517 * rails-api/active_model_serializers#354 (comment)
…xed_json` method Default Mongoid serialization keeps the `_id` property in the JSON as "BSON Object", which breaks Elasticsearch. See: * elastic/elasticsearch#3517 * rails-api/active_model_serializers#354 (comment)
…xed_json` method Default Mongoid serialization keeps the `_id` property in the JSON as "BSON Object", which breaks Elasticsearch. See: * elastic/elasticsearch#3517 * rails-api/active_model_serializers#354 (comment)
…xed_json` method Default Mongoid serialization keeps the `_id` property in the JSON as "BSON Object", which breaks Elasticsearch. See: * elastic/elasticsearch#3517 * rails-api/active_model_serializers#354 (comment)
…xed_json` method Default Mongoid serialization keeps the `_id` property in the JSON as "BSON Object", which breaks Elasticsearch. See: * elastic/elasticsearch#3517 * rails-api/active_model_serializers#354 (comment)
…xed_json` method Default Mongoid serialization keeps the `_id` property in the JSON as "BSON Object", which breaks Elasticsearch. See: * elastic/elasticsearch#3517 * rails-api/active_model_serializers#354 (comment)
…xed_json` method Default Mongoid serialization keeps the `_id` property in the JSON as "BSON Object", which breaks Elasticsearch. See: * elastic/elasticsearch#3517 * rails-api/active_model_serializers#354 (comment)
…xed_json` method Default Mongoid serialization keeps the `_id` property in the JSON as "BSON Object", which breaks Elasticsearch. See: * elastic/elasticsearch#3517 * rails-api/active_model_serializers#354 (comment)
…xed_json` method Default Mongoid serialization keeps the `_id` property in the JSON as "BSON Object", which breaks Elasticsearch. See: * elastic/elasticsearch#3517 * rails-api/active_model_serializers#354 (comment)
…xed_json` method Default Mongoid serialization keeps the `_id` property in the JSON as "BSON Object", which breaks Elasticsearch. See: * elastic/elasticsearch#3517 * rails-api/active_model_serializers#354 (comment)
…xed_json` method Default Mongoid serialization keeps the `_id` property in the JSON as "BSON Object", which breaks Elasticsearch. See: * elastic/elasticsearch#3517 * rails-api/active_model_serializers#354 (comment)
Expected Behavior
Normally, if you try to index a document without an ID in the URI (e.g. a POST) but with an _id field in the document (and no explicit _id path mapping), it throws an error because the autogenerated ID does not match the provided _id field:
Broken Behavior
However, if the _id field happens to be an object, Elasticsearch happily indexes the document:
You can GET it:
curl -XGET localhost:9200/testindex/testtype/BsTbRqaeTrKLIe0JoeHsWw?pretty
It shows up with a match_all query:
But doesn't show up when you search for exact values (or Match or any other search):
If you ask ES why it doesn't show up, it says there are no matching terms:
And finally, as a fun twist, you can set an explicit mapping to look inside the _id object. This works with regard to the ID (it extracts the appropriate ID), is GETable, match_all, etc. Search is still broken.
Reference
This was surfaced by Scott on the mailing list.
The text was updated successfully, but these errors were encountered: