-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mapper: Throw exception if null_value is set to null
The mapping parser should throw an exception if "null_value" is set to `null`. Fixes #7273 ```bash 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 } ```
- Loading branch information
1 parent
617815d
commit 49374db
Showing
11 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/test/java/org/elasticsearch/index/mapper/null_value/NullValueTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.elasticsearch.index.mapper.null_value; | ||
|
||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
|
||
import org.elasticsearch.common.settings.ImmutableSettings; | ||
import org.elasticsearch.common.xcontent.XContentFactory; | ||
import org.elasticsearch.index.mapper.MapperParsingException; | ||
import org.elasticsearch.index.service.IndexService; | ||
import org.elasticsearch.test.ElasticsearchSingleNodeTest; | ||
import org.junit.Test; | ||
|
||
import static org.hamcrest.Matchers.*; | ||
|
||
/** | ||
*/ | ||
public class NullValueTests extends ElasticsearchSingleNodeTest { | ||
|
||
@Test | ||
public void testNullNull_Value() throws Exception { | ||
IndexService indexService = createIndex("test", ImmutableSettings.settingsBuilder().build()); | ||
String[] typesToTest = {"integer", "long", "double", "float", "short", "date", "ip", "string", "boolean", "byte"}; | ||
|
||
for (String type : typesToTest) { | ||
String mapping = XContentFactory.jsonBuilder() | ||
.startObject() | ||
.startObject("type") | ||
.startObject("properties") | ||
.startObject("numeric") | ||
.field("type", type) | ||
.field("null_value", (String) null) | ||
.endObject() | ||
.endObject() | ||
.endObject() | ||
.endObject().string(); | ||
|
||
try { | ||
indexService.mapperService().documentMapperParser().parse(mapping); | ||
fail("Test should have failed because [null_value] was null."); | ||
} catch (MapperParsingException e) { | ||
assertThat(e.getMessage(), equalTo("Property [null_value] cannot be null.")); | ||
} | ||
|
||
} | ||
|
||
|
||
} | ||
} |