diff --git a/core/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java index 53393183b55..589670fcccd 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/FieldMapper.java @@ -21,6 +21,7 @@ package org.elasticsearch.index.mapper; import com.carrotsearch.hppc.cursors.ObjectCursor; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; + import org.apache.lucene.document.FieldType; import org.apache.lucene.index.IndexOptions; import org.apache.lucene.index.IndexableField; diff --git a/core/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java index 83ebd6d9fb5..80dc01a965f 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/NumberFieldMapper.java @@ -85,6 +85,12 @@ public class NumberFieldMapper extends FieldMapper { return builder; } + @Override + public Builder indexOptions(IndexOptions indexOptions) { + throw new MapperParsingException( + "index_options not allowed in field [" + name + "] of type [" + builder.fieldType().typeName() + "]"); + } + protected Explicit ignoreMalformed(BuilderContext context) { if (ignoreMalformed != null) { return new Explicit<>(ignoreMalformed, true); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/NumberFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/NumberFieldMapperTests.java index 65ba83a7ab3..afbf63a23bd 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/NumberFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/NumberFieldMapperTests.java @@ -31,9 +31,9 @@ import org.elasticsearch.index.mapper.NumberFieldTypeTests.OutOfRangeSpec; import java.io.ByteArrayInputStream; import java.io.IOException; import java.math.BigInteger; -import java.util.List; import java.util.Arrays; import java.util.HashSet; +import java.util.List; import static org.hamcrest.Matchers.containsString; @@ -41,7 +41,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase { @Override protected void setTypeList() { - TYPES = new HashSet<>(Arrays.asList("byte", "short", "integer", "long", "float", "double")); + TYPES = new HashSet<>(Arrays.asList("byte", "short", "integer", "long", "float", "double", "half_float")); WHOLE_TYPES = new HashSet<>(Arrays.asList("byte", "short", "integer", "long")); } @@ -258,7 +258,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase { public void testRejectNorms() throws IOException { // not supported as of 5.0 - for (String type : Arrays.asList("byte", "short", "integer", "long", "float", "double")) { + for (String type : TYPES) { DocumentMapperParser parser = createIndex("index-" + type).mapperService().documentMapperParser(); String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties") @@ -273,6 +273,25 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase { } } + /** + * `index_options` was deprecated and is rejected as of 7.0 + */ + public void testRejectIndexOptions() throws IOException { + for (String type : TYPES) { + DocumentMapperParser parser = createIndex("index-" + type).mapperService().documentMapperParser(); + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") + .startObject("properties") + .startObject("foo") + .field("type", type) + .field("index_options", randomFrom(new String[] { "docs", "freqs", "positions", "offsets" })) + .endObject() + .endObject().endObject().endObject().string(); + MapperParsingException e = expectThrows(MapperParsingException.class, + () -> parser.parse("type", new CompressedXContent(mapping))); + assertThat(e.getMessage(), containsString("index_options not allowed in field [foo] of type [" + type +"]")); + } + } + @Override protected void doTestNullValue(String type) throws IOException { String mapping = XContentFactory.jsonBuilder().startObject() @@ -296,7 +315,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase { assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field")); Object missing; - if (Arrays.asList("float", "double").contains(type)) { + if (Arrays.asList("float", "double", "half_float").contains(type)) { missing = 123d; } else { missing = 123L; diff --git a/docs/reference/mapping/params/index-options.asciidoc b/docs/reference/mapping/params/index-options.asciidoc index 8d180e4f988..e2cd6ce20e1 100644 --- a/docs/reference/mapping/params/index-options.asciidoc +++ b/docs/reference/mapping/params/index-options.asciidoc @@ -28,6 +28,8 @@ following settings: offsets (which map the term back to the original string) are indexed. Offsets are used by the <> to speed up highlighting. +NOTE: <> don't support the `index_options` parameter any longer. + <> string fields use `positions` as the default, and all other fields use `docs` as the default. diff --git a/docs/reference/migration/migrate_7_0/mappings.asciidoc b/docs/reference/migration/migrate_7_0/mappings.asciidoc index e702265f9a1..4f8893829f9 100644 --- a/docs/reference/migration/migrate_7_0/mappings.asciidoc +++ b/docs/reference/migration/migrate_7_0/mappings.asciidoc @@ -3,4 +3,8 @@ ==== The `_all` meta field is removed -The `_all` field deprecated in 6 have now been removed. \ No newline at end of file +The `_all` field deprecated in 6 have now been removed. + +==== `index_options` for numeric fields has been removed + +The `index_options` field for numeric fields has been deprecated in 6 and has now been removed. \ No newline at end of file diff --git a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java index cee3a597e2b..bacd98c3133 100644 --- a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java +++ b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java @@ -88,6 +88,12 @@ public class ScaledFloatFieldMapper extends FieldMapper { return builder; } + @Override + public Builder indexOptions(IndexOptions indexOptions) { + throw new MapperParsingException( + "index_options not allowed in field [" + name + "] of type [" + builder.fieldType().typeName() + "]"); + } + protected Explicit ignoreMalformed(BuilderContext context) { if (ignoreMalformed != null) { return new Explicit<>(ignoreMalformed, true); diff --git a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapperTests.java index 42f8bff5449..29e68c85db5 100644 --- a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapperTests.java @@ -336,4 +336,19 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase { ); assertThat(e.getMessage(), containsString("name cannot be empty string")); } + + /** + * `index_options` was deprecated and is rejected as of 7.0 + */ + public void testRejectIndexOptions() throws IOException { + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") + .startObject("properties") + .startObject("foo") + .field("type", "scaled_float") + .field("index_options", randomFrom(new String[] { "docs", "freqs", "positions", "offsets" })) + .endObject() + .endObject().endObject().endObject().string(); + MapperParsingException e = expectThrows(MapperParsingException.class, () -> parser.parse("type", new CompressedXContent(mapping))); + assertThat(e.getMessage(), containsString("index_options not allowed in field [foo] of type [scaled_float]")); + } }