Skip to content
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

Throw exception when content _id is an object #3586

Closed

Conversation

polyfractal
Copy link
Contributor

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 and 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 #3517

    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
@@ -307,6 +307,8 @@ protected Field parseCreateField(ParseContext context) throws IOException {
return null;
}
return new Field(names.indexName(), context.id(), fieldType);
} else if (parser.currentName() != null && parser.currentName().equals(Defaults.NAME) && parser.currentToken().equals(XContentParser.Token.START_OBJECT)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could remove the null check by changing the second check to Defaults.NAME.equals(parser.currentName())

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the first check should be:

if (parser.currentName() != null && parser.currentName().equals(Defaults.NAME)) {
  if (parser.currentToken().isValue() == false) {
    throw new MapperParsingException("Expected a value as Content id but got " + parser.currentToken());
  }
/....
}

that way we also fail for arrays etc.

@spinscale
Copy link
Contributor

is there any specific reason (except breaking current behaviour), why this is hanging around?

@clintongormley
Copy link
Contributor

@polyfractal ping?

@polyfractal
Copy link
Contributor Author

@spinscale No particular reason, just got lost in the shuffle I think.

For the record: I have no idea if this PR is a good idea, and if this is the best way to do it. Was a quick one-line PR that I sent before I really had a good handle on the ES codebase.

@s1monw
Copy link
Contributor

s1monw commented Jul 17, 2014

I left a comment, can reabase it and update ? I think it's a good change

@clintongormley
Copy link
Contributor

@polyfractal reassigning this to you.

@clintongormley
Copy link
Contributor

Closing in favour of #6730

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

Successfully merging this pull request may close these issues.

If _id field is an object, no error is thrown but doc is "unsearchable"
5 participants