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

Fix error applying ignore_malformed to boolean values #41261

Merged
merged 3 commits into from
Apr 17, 2019

Conversation

cbuescher
Copy link
Member

The ignore_malformed option currently works on numeric fields only when the
bad value isn't a string value but not if it is a boolean. In this case we get a
parsing error from the xContent parser which we need to catch in addition to the
field mapper.

Closes #11498

The `ignore_malformed` option currently works on numeric fields only when the
bad value isn't a string value but not if it is a boolean. In this case we get a
parsing error from the xContent parser which we need to catch in addition to the
field mapper.

Closes elastic#11498
@cbuescher cbuescher added >bug :Search Foundations/Mapping Index mappings, including merging and defining field types v8.0.0 v7.2.0 v7.0.1 labels Apr 16, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

Copy link
Contributor

@jtibshirani jtibshirani left a comment

Choose a reason for hiding this comment

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

This looks good to me overall, I left a question to make sure I understand the approach.

@@ -1042,7 +1044,7 @@ protected void parseCreateField(ParseContext context, List<IndexableField> field
} else {
try {
numericValue = fieldType().type.parse(parser, coerce.value());
} catch (IllegalArgumentException e) {
} catch (IllegalArgumentException | JsonParseException e) {
Copy link
Contributor

@jtibshirani jtibshirani Apr 16, 2019

Choose a reason for hiding this comment

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

I haven't tested this, but I wanted to check that this will not introduce too much leniency. In particular, I'm wondering what happens if we try to pass a JSON object to a numeric field with ignore_malformed enabled.

Copy link
Member Author

Choose a reason for hiding this comment

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

The way the parser works, anything that's not a number or string token after the field name should throw an error. If "swallowing" that token with ignore_malformed leads to unparseable xcontent afterwards we will still throw an error. I think that's what should happen.

Copy link
Contributor

@jtibshirani jtibshirani Apr 16, 2019

Choose a reason for hiding this comment

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

Thanks for clarifying. What would you think about adding a check whether the token is a value, as in if (ignoreMalformed.value() && parser.currentToken().isValue()) { ... }? That way a user would get a clear, localized error like "Current token (START_OBJECT) not numeric", as opposed to a more difficult one to track down like "Malformed content, found extra data after parsing: END_OBJECT".

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem with that is that the code actually throwing the exception is in the jackson library. The only way I could think of to do this is either have some logic taking apart the exception or pre-checking the token in NumberFieldMapper. I'd try to avoid the former, was the later what you had in mind? We'd need to test for (and accept) all value tokens here basically?

Christoph Büscher added 2 commits April 16, 2019 22:24
@cbuescher
Copy link
Member Author

@jtibshirani thanks for the review, I added the check for the token type you suggested and added a test where the malformed field value is an object. The current implementation will throw erros in numeric fields foo like:

{
   foo: { "someField" : "someValue" } 
}

regardless of the ignore_malformed setting. Not sure if that is what the user would expect here. As an alternative we could skip the whole object in case ignore_malformed is true. What do you think is the more intuitive behaviour in these edge cases?

Copy link
Contributor

@jtibshirani jtibshirani left a comment

Choose a reason for hiding this comment

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

Thanks @cbuescher, this looks good to me. My intuition is that the whole object should be skipped, but it might make sense to address the object case in a future PR since there is a separate issue for it with quite a bit of discussion (#12366).

@cbuescher
Copy link
Member Author

@jtibshirani thanks for the review, and +1 to tackling the object case as a follow up, e.g. when tackling the issue you linked.

@cbuescher cbuescher merged commit c31a5b1 into elastic:master Apr 17, 2019
cbuescher pushed a commit that referenced this pull request Apr 17, 2019
The `ignore_malformed` option currently works on numeric fields only when the
bad value isn't a string value but not if it is a boolean. In this case we get a
parsing error from the xContent parser which we need to catch in addition to the
field mapper.

Closes #11498
cbuescher pushed a commit that referenced this pull request Apr 17, 2019
The `ignore_malformed` option currently works on numeric fields only when the
bad value isn't a string value but not if it is a boolean. In this case we get a
parsing error from the xContent parser which we need to catch in addition to the
field mapper.

Closes #11498
gurkankaymak pushed a commit to gurkankaymak/elasticsearch that referenced this pull request May 27, 2019
The `ignore_malformed` option currently works on numeric fields only when the
bad value isn't a string value but not if it is a boolean. In this case we get a
parsing error from the xContent parser which we need to catch in addition to the
field mapper.

Closes elastic#11498
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search Foundations/Mapping Index mappings, including merging and defining field types v7.0.1 v7.2.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] 'ignore_malformed' applied to a malformed (boolean) numeric field does not work
4 participants