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 if null_value is set to null #7978

Closed

Conversation

polyfractal
Copy link
Contributor

The mapping parser should throw an exception if "null_value" is set to null.

Fixes #7273

PUT /foo
{
  "mappings": {
    "bar": {
      "properties": {
        "exception": {
          "null_value": null,
          "type": "integer"
        }
      }
    }
  }
}
{
   "error": "MapperParsingException[mapping [bar]]; nested: MapperParsingException[Property [null_value] cannot be null.]; ",
   "status": 400
}

As a side note, looks like there are a lot of other properties which could be set to null and throw similar errors: https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/index/mapper/core/TypeParsers.java#L146-L187

I'm not sure the best way to handle these other than an explicit check for nullness inside each clause...which seems gross.

@rjernst
Copy link
Member

rjernst commented Oct 3, 2014

LGTM.

@s1monw
Copy link
Contributor

s1monw commented Oct 6, 2014

LGTM

@s1monw
Copy link
Contributor

s1monw commented Oct 6, 2014

I think this should go into 1.3 and 1.4 et.al - I labeled the issues accordingly

@polyfractal
Copy link
Contributor Author

Merged in master: 4e2dd77, 1.x: fcea4c5, 1.4: 4b5b01f, 1.3: 49374db

@clintongormley clintongormley changed the title Mapper: Throw exception if null_value is set to null Mapping: Throw exception if null_value is set to null Nov 3, 2014
@clintongormley clintongormley added v1.5.0 :Search Foundations/Mapping Index mappings, including merging and defining field types labels Mar 19, 2015
@clintongormley clintongormley changed the title Mapping: Throw exception if null_value is set to null Throw exception if null_value is set to null Jun 7, 2015
romseygeek added a commit that referenced this pull request Sep 1, 2020
Several field mappers have a null_value parameter, that allows you to specify a placeholder
value to insert into a document if the incoming value for that field is null. The default value
for this is always null, meaning "add no placeholder". However, we explicitly bar users from
setting this parameter directly to null (done in #7978, in order to fix an NPE).

This exclusion means that if a mapper is serialized with include_defaults, then we either need
to special-case null_value to ensure that it is not output when it holds the default value, or
we find that the resulting serialized form cannot be used to create a mapping. This stops us
doing some useful generic testing of mappers.

This commit permits null as a parameter value for null_value, and changes the tests to check
that it is a) permissible and b) applied without throwing errors. As part of the testing changes,
a new base class MapperServiceTestCase is refactored from MapperTestCase, holding
the various helper methods related to building mappings but not the single-mapper specific
abstract methods.

Closes #58823
romseygeek added a commit to romseygeek/elasticsearch that referenced this pull request Sep 1, 2020
Several field mappers have a null_value parameter, that allows you to specify a placeholder
value to insert into a document if the incoming value for that field is null. The default value
for this is always null, meaning "add no placeholder". However, we explicitly bar users from
setting this parameter directly to null (done in elastic#7978, in order to fix an NPE).

This exclusion means that if a mapper is serialized with include_defaults, then we either need
to special-case null_value to ensure that it is not output when it holds the default value, or
we find that the resulting serialized form cannot be used to create a mapping. This stops us
doing some useful generic testing of mappers.

This commit permits null as a parameter value for null_value, and changes the tests to check
that it is a) permissible and b) applied without throwing errors. As part of the testing changes,
a new base class MapperServiceTestCase is refactored from MapperTestCase, holding
the various helper methods related to building mappings but not the single-mapper specific
abstract methods.

Closes elastic#58823
romseygeek added a commit that referenced this pull request Sep 2, 2020
Several field mappers have a null_value parameter, that allows you to specify a placeholder
value to insert into a document if the incoming value for that field is null. The default value
for this is always null, meaning "add no placeholder". However, we explicitly bar users from
setting this parameter directly to null (done in #7978, in order to fix an NPE).

This exclusion means that if a mapper is serialized with include_defaults, then we either need
to special-case null_value to ensure that it is not output when it holds the default value, or
we find that the resulting serialized form cannot be used to create a mapping. This stops us
doing some useful generic testing of mappers.

This commit permits null as a parameter value for null_value, and changes the tests to check
that it is a) permissible and b) applied without throwing errors. As part of the testing changes,
a new base class MapperServiceTestCase is refactored from MapperTestCase, holding
the various helper methods related to building mappings but not the single-mapper specific
abstract methods.

Closes #58823
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 v1.3.5 v1.4.0 v1.5.0 v2.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants