Reject the `index_options` parameter for numeric fields (#26668)
Numeric fields no longer support the index_options parameter. This changes the parameter to be rejected in numeric field types after it was deprecated in 6.0. Closes #21475
This commit is contained in:
parent
530d80fdc1
commit
6189c54c84
|
@ -21,6 +21,7 @@ package org.elasticsearch.index.mapper;
|
||||||
|
|
||||||
import com.carrotsearch.hppc.cursors.ObjectCursor;
|
import com.carrotsearch.hppc.cursors.ObjectCursor;
|
||||||
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
|
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
|
||||||
|
|
||||||
import org.apache.lucene.document.FieldType;
|
import org.apache.lucene.document.FieldType;
|
||||||
import org.apache.lucene.index.IndexOptions;
|
import org.apache.lucene.index.IndexOptions;
|
||||||
import org.apache.lucene.index.IndexableField;
|
import org.apache.lucene.index.IndexableField;
|
||||||
|
|
|
@ -85,6 +85,12 @@ public class NumberFieldMapper extends FieldMapper {
|
||||||
return builder;
|
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<Boolean> ignoreMalformed(BuilderContext context) {
|
protected Explicit<Boolean> ignoreMalformed(BuilderContext context) {
|
||||||
if (ignoreMalformed != null) {
|
if (ignoreMalformed != null) {
|
||||||
return new Explicit<>(ignoreMalformed, true);
|
return new Explicit<>(ignoreMalformed, true);
|
||||||
|
|
|
@ -31,9 +31,9 @@ import org.elasticsearch.index.mapper.NumberFieldTypeTests.OutOfRangeSpec;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setTypeList() {
|
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"));
|
WHOLE_TYPES = new HashSet<>(Arrays.asList("byte", "short", "integer", "long"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,7 +258,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
|
||||||
|
|
||||||
public void testRejectNorms() throws IOException {
|
public void testRejectNorms() throws IOException {
|
||||||
// not supported as of 5.0
|
// 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();
|
DocumentMapperParser parser = createIndex("index-" + type).mapperService().documentMapperParser();
|
||||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
|
||||||
.startObject("properties")
|
.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
|
@Override
|
||||||
protected void doTestNullValue(String type) throws IOException {
|
protected void doTestNullValue(String type) throws IOException {
|
||||||
String mapping = XContentFactory.jsonBuilder().startObject()
|
String mapping = XContentFactory.jsonBuilder().startObject()
|
||||||
|
@ -296,7 +315,7 @@ public class NumberFieldMapperTests extends AbstractNumericFieldMapperTestCase {
|
||||||
assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field"));
|
assertArrayEquals(new IndexableField[0], doc.rootDoc().getFields("field"));
|
||||||
|
|
||||||
Object missing;
|
Object missing;
|
||||||
if (Arrays.asList("float", "double").contains(type)) {
|
if (Arrays.asList("float", "double", "half_float").contains(type)) {
|
||||||
missing = 123d;
|
missing = 123d;
|
||||||
} else {
|
} else {
|
||||||
missing = 123L;
|
missing = 123L;
|
||||||
|
|
|
@ -28,6 +28,8 @@ following settings:
|
||||||
offsets (which map the term back to the original string) are indexed.
|
offsets (which map the term back to the original string) are indexed.
|
||||||
Offsets are used by the <<unified-highlighter,unified highlighter>> to speed up highlighting.
|
Offsets are used by the <<unified-highlighter,unified highlighter>> to speed up highlighting.
|
||||||
|
|
||||||
|
NOTE: <<number,Numeric fields>> don't support the `index_options` parameter any longer.
|
||||||
|
|
||||||
<<mapping-index,Analyzed>> string fields use `positions` as the default, and
|
<<mapping-index,Analyzed>> string fields use `positions` as the default, and
|
||||||
all other fields use `docs` as the default.
|
all other fields use `docs` as the default.
|
||||||
|
|
||||||
|
|
|
@ -4,3 +4,7 @@
|
||||||
==== The `_all` meta field is removed
|
==== The `_all` meta field is removed
|
||||||
|
|
||||||
The `_all` field deprecated in 6 have now been removed.
|
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.
|
|
@ -88,6 +88,12 @@ public class ScaledFloatFieldMapper extends FieldMapper {
|
||||||
return builder;
|
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<Boolean> ignoreMalformed(BuilderContext context) {
|
protected Explicit<Boolean> ignoreMalformed(BuilderContext context) {
|
||||||
if (ignoreMalformed != null) {
|
if (ignoreMalformed != null) {
|
||||||
return new Explicit<>(ignoreMalformed, true);
|
return new Explicit<>(ignoreMalformed, true);
|
||||||
|
|
|
@ -336,4 +336,19 @@ public class ScaledFloatFieldMapperTests extends ESSingleNodeTestCase {
|
||||||
);
|
);
|
||||||
assertThat(e.getMessage(), containsString("name cannot be empty string"));
|
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]"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue