Skip to content

Allow empty null values for date and IP field mappers #62487

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

Merged
merged 5 commits into from
Sep 17, 2020

Conversation

romseygeek
Copy link
Contributor

@romseygeek romseygeek commented Sep 16, 2020

In #57666 we changed when null_value was parsed for ip and date fields. Previously,
the null value was stored as a string, and parsed into a date or InetAddress whenever
a document containing a null value was encountered. Now, the values are parsed when
the mappings are built, which means that bad values are detected up front; if you try and
add a mapping with a badly-parsed ip or date for a null_value, the mapping will be
rejected.

This causes problems for upgrades in the case when you have a badly-formed null_value
in a pre-7.9 cluster. This commit fixes the upgrade case by changing the logic to only
fail on indexes created in 8x and later. For earlier indexes, we log a warning on the
badly formed value and ignore it, replicating the earlier behaviour.

Fixes #62363

@romseygeek romseygeek added >bug :Search Foundations/Mapping Index mappings, including merging and defining field types v8.0.0 v7.10.0 v7.9.2 labels Sep 16, 2020
@romseygeek romseygeek self-assigned this Sep 16, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/Mapping)

@elasticmachine elasticmachine added the Team:Search Meta label for search team label Sep 16, 2020
@@ -28,61 +28,28 @@
import org.apache.lucene.util.BytesRef;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This also converts IpFieldMapperTests to MapperTestCase because it just makes testing so much easier...

String mapping = Strings.toString(XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("field").field("type", "ip").endObject().endObject()
.endObject().endObject());
mapper = createDocumentMapper(fieldMapping(b -> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the part that is testing the new functionality


public void testEmptyName() throws IOException {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

testEmptyName and testSerializeDefaults are done as part of the parent class tests. testMeta in the parent class discovered that IpFieldMapper wasn't correctly serializing its meta param, so the test cutover is definitely worth it!

Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

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

@romseygeek and I talked about a general question I was having. At least on Masters DateFieldMapper, the “null_value” Parameter is initialized as non-updateable. From the issue underlying the PR I thought the idea for the user updating from an old cluster with “bad” null_value is to set it to “”, so the idea now is to to log a warning for "bad" formatted null_values if the index created version is < 8x, and reject otherwise. Please correct me if I'm missing sth.

@romseygeek
Copy link
Contributor Author

I've updated the PR to take into account @cbuescher 's points. We now fail for indexes created in 8x, but emit a warning and treat the badly-formed null values as null in 7x.

Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

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

LGTM, left one question but only for my own education.

@Override
protected List<Parameter<?>> getParameters() {
return List.of(indexed, hasDocValues, stored, ignoreMalformed, nullValue);
return List.of(indexed, hasDocValues, stored, ignoreMalformed, nullValue, meta);
Copy link
Member

Choose a reason for hiding this comment

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

I guess the missing "meta" was discovered by the test change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes!

@romseygeek romseygeek merged commit 7b50618 into elastic:master Sep 17, 2020
@romseygeek romseygeek deleted the mapper/date-empty-null-value branch September 17, 2020 15:18
romseygeek added a commit that referenced this pull request Sep 17, 2020
In #57666 we changed when null_value was parsed for ip and date fields. Previously,
the null value was stored as a string, and parsed into a date or InetAddress whenever
a document containing a null value was encountered. Now, the values are parsed when
the mappings are built, which means that bad values are detected up front; if you try and
add a mapping with a badly-parsed ip or date for a null_value, the mapping will be
rejected.

This causes problems for upgrades in the case when you have a badly-formed null_value
in a pre-7.9 cluster. This commit fixes the upgrade case by changing the logic to only
logging a warning on the badly formed value, replicating the earlier behaviour.

Fixes #62363
romseygeek added a commit that referenced this pull request Sep 17, 2020
In #57666 we changed when null_value was parsed for ip and date fields. Previously,
the null value was stored as a string, and parsed into a date or InetAddress whenever
a document containing a null value was encountered. Now, the values are parsed when
the mappings are built, which means that bad values are detected up front; if you try and
add a mapping with a badly-parsed ip or date for a null_value, the mapping will be
rejected.

This causes problems for upgrades in the case when you have a badly-formed null_value
in a pre-7.9 cluster. This commit fixes the upgrade case by changing the logic to only
logging a warning on the badly formed value, replicating the earlier behaviour.

Fixes #62363
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 Team:Search Meta label for search team v7.9.2 v7.10.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setting empty string as null_value in date field breaks 7.9 upgrade
4 participants