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 e4bd5f90733..b92d5c6780f 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 @@ -72,6 +72,10 @@ public class ScaledFloatFieldMapper extends FieldMapper { public static final String CONTENT_TYPE = "scaled_float"; // use the same default as numbers private static final Setting COERCE_SETTING = NumberFieldMapper.COERCE_SETTING; + private static final FieldType FIELD_TYPE = new FieldType(); + static { + FIELD_TYPE.setIndexOptions(IndexOptions.DOCS); + } public static class Builder extends FieldMapper.Builder { @@ -82,7 +86,7 @@ public class ScaledFloatFieldMapper extends FieldMapper { private Double nullValue; public Builder(String name) { - super(name, new FieldType()); + super(name, FIELD_TYPE); builder = this; } diff --git a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RankFeatureFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RankFeatureFieldMapperTests.java index 454162579cb..6b9513e9508 100644 --- a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RankFeatureFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RankFeatureFieldMapperTests.java @@ -45,7 +45,7 @@ public class RankFeatureFieldMapperTests extends FieldMapperTestCase unsupportedProperties() { - return org.elasticsearch.common.collect.Set.of("analyzer", "similarity", "store", "doc_values"); + return org.elasticsearch.common.collect.Set.of("analyzer", "similarity", "store", "doc_values", "index"); } @Before diff --git a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RankFeaturesFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RankFeaturesFieldMapperTests.java index aa5f43941de..8541ca21b42 100644 --- a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RankFeaturesFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/RankFeaturesFieldMapperTests.java @@ -40,7 +40,7 @@ public class RankFeaturesFieldMapperTests extends FieldMapperTestCase unsupportedProperties() { - return org.elasticsearch.common.collect.Set.of("analyzer", "similarity", "store", "doc_values"); + return org.elasticsearch.common.collect.Set.of("analyzer", "similarity", "store", "doc_values", "index"); } IndexService indexService; diff --git a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java index 086d675e44d..df44b8aaad4 100644 --- a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java +++ b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java @@ -658,7 +658,7 @@ public class ICUCollationKeywordFieldMapper extends FieldMapper { @Override protected void doXContentBody(XContentBuilder builder, boolean includeDefaults, Params params) throws IOException { super.doXContentBody(builder, includeDefaults, params); - if (includeDefaults || (mappedFieldType.isSearchable() && fieldType.indexOptions() != IndexOptions.DOCS)) { + if (fieldType.indexOptions() != IndexOptions.NONE && (includeDefaults || fieldType.indexOptions() != IndexOptions.DOCS)) { builder.field("index_options", indexOptionToString(fieldType.indexOptions())); } if (nullValue != null) { diff --git a/plugins/mapper-murmur3/src/test/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapperTests.java b/plugins/mapper-murmur3/src/test/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapperTests.java index 86d56fa7f3a..dc7a8becdea 100644 --- a/plugins/mapper-murmur3/src/test/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapperTests.java +++ b/plugins/mapper-murmur3/src/test/java/org/elasticsearch/index/mapper/murmur3/Murmur3FieldMapperTests.java @@ -58,7 +58,7 @@ public class Murmur3FieldMapperTests extends FieldMapperTestCase unsupportedProperties() { - return org.elasticsearch.common.collect.Set.of("analyzer", "similarity", "doc_values"); + return org.elasticsearch.common.collect.Set.of("analyzer", "similarity", "doc_values", "index"); } @Before diff --git a/server/src/internalClusterTest/java/org/elasticsearch/indices/mapping/SimpleGetFieldMappingsIT.java b/server/src/internalClusterTest/java/org/elasticsearch/indices/mapping/SimpleGetFieldMappingsIT.java index 6b68e7fe297..a8742c1fe96 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/indices/mapping/SimpleGetFieldMappingsIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/indices/mapping/SimpleGetFieldMappingsIT.java @@ -148,9 +148,11 @@ public class SimpleGetFieldMappingsIT extends ESIntegTestCase { public void testSimpleGetFieldMappingsWithDefaults() throws Exception { assertAcked(prepareCreate("test").addMapping("type", getMappingForType("type"))); client().admin().indices().preparePutMapping("test").setType("type").setSource("num", "type=long").get(); + client().admin().indices().preparePutMapping("test").setType("type") + .setSource("field2", "type=text,index=false").get(); GetFieldMappingsResponse response = client().admin().indices().prepareGetFieldMappings() - .setFields("num", "field1", "obj.subfield").includeDefaults(true).get(); + .setFields("num", "field1", "field2", "obj.subfield").includeDefaults(true).get(); assertThat((Map) response.fieldMappings("test", "type", "num").sourceAsMap().get("num"), hasEntry("index", Boolean.TRUE)); @@ -160,6 +162,8 @@ public class SimpleGetFieldMappingsIT extends ESIntegTestCase { hasEntry("index", Boolean.TRUE)); assertThat((Map) response.fieldMappings("test", "type", "field1").sourceAsMap().get("field1"), hasEntry("type", "text")); + assertThat((Map) response.fieldMappings("test", "type", "field2").sourceAsMap().get("field2"), + hasEntry("type", "text")); assertThat((Map) response.fieldMappings("test", "type", "obj.subfield").sourceAsMap().get("subfield"), hasEntry("type", "keyword")); } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/AbstractGeometryFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/AbstractGeometryFieldMapper.java index e44c0cc2244..b29a592186b 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/AbstractGeometryFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/AbstractGeometryFieldMapper.java @@ -19,6 +19,7 @@ package org.elasticsearch.index.mapper; import org.apache.lucene.document.FieldType; +import org.apache.lucene.index.IndexOptions; import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.Term; import org.apache.lucene.search.DocValuesFieldExistsQuery; @@ -61,6 +62,7 @@ public abstract class AbstractGeometryFieldMapper extends Fie static { FIELD_TYPE.setStored(false); FIELD_TYPE.setOmitNorms(true); + FIELD_TYPE.setIndexOptions(IndexOptions.DOCS); FIELD_TYPE.freeze(); } } diff --git a/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java index 5f435c125a4..d8400ba75cd 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/GeoPointFieldMapper.java @@ -22,6 +22,7 @@ import org.apache.lucene.document.FieldType; import org.apache.lucene.document.LatLonDocValuesField; import org.apache.lucene.document.LatLonPoint; import org.apache.lucene.document.StoredField; +import org.apache.lucene.index.IndexOptions; import org.apache.lucene.index.IndexableField; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.Explicit; @@ -49,6 +50,7 @@ public class GeoPointFieldMapper extends AbstractPointGeometryFieldMapper unsupportedProperties() { - return org.elasticsearch.common.collect.Set.of("analyzer", "eager_global_ordinals", "norms", "similarity"); + return org.elasticsearch.common.collect.Set.of("analyzer", "eager_global_ordinals", "norms", "similarity", "index"); } @Override diff --git a/server/src/test/java/org/elasticsearch/index/mapper/CompletionFieldMapperTests.java b/server/src/test/java/org/elasticsearch/index/mapper/CompletionFieldMapperTests.java index cd5b1f72f99..4b7683a8a2f 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/CompletionFieldMapperTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/CompletionFieldMapperTests.java @@ -83,7 +83,7 @@ public class CompletionFieldMapperTests extends FieldMapperTestCase unsupportedProperties() { - return org.elasticsearch.common.collect.Set.of("doc_values"); + return org.elasticsearch.common.collect.Set.of("doc_values", "index"); } @Override diff --git a/test/framework/src/main/java/org/elasticsearch/index/mapper/FieldMapperTestCase.java b/test/framework/src/main/java/org/elasticsearch/index/mapper/FieldMapperTestCase.java index 0609e218b6a..7a0cc06653a 100644 --- a/test/framework/src/main/java/org/elasticsearch/index/mapper/FieldMapperTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/index/mapper/FieldMapperTestCase.java @@ -95,6 +95,7 @@ public abstract class FieldMapperTestCase> exte b.docValues(false); }), booleanModifier("eager_global_ordinals", true, (a, t) -> a.setEagerGlobalOrdinals(t)), + booleanModifier("index", false, (a, t) -> a.index(t)), booleanModifier("norms", false, FieldMapper.Builder::omitNorms), new Modifier("search_analyzer", true, (a, b) -> { a.searchAnalyzer(new NamedAnalyzer("standard", AnalyzerScope.INDEX, new StandardAnalyzer())); @@ -228,22 +229,27 @@ public abstract class FieldMapperTestCase> exte Mapper.BuilderContext context = new Mapper.BuilderContext(SETTINGS, new ContentPath(1)); - XContentBuilder x = JsonXContent.contentBuilder(); - x.startObject().startObject("properties"); - builder.build(context).toXContent(x, ToXContent.EMPTY_PARAMS); - x.endObject().endObject(); - String mappings = Strings.toString(x); + String mappings = mappingsToString(builder.build(context), false); + String mappingsWithDefault = mappingsToString(builder.build(context), true); mapperService.merge("_doc", new CompressedXContent(mappings), MapperService.MergeReason.MAPPING_UPDATE); Mapper rebuilt = mapperService.documentMapper().mappers().getMapper(builder.name); - x = JsonXContent.contentBuilder(); - x.startObject().startObject("properties"); - rebuilt.toXContent(x, ToXContent.EMPTY_PARAMS); - x.endObject().endObject(); - String reparsed = Strings.toString(x); + String reparsed = mappingsToString(rebuilt, false); + String reparsedWithDefault = mappingsToString(rebuilt, true); assertThat(reparsed, equalTo(mappings)); + assertThat(reparsedWithDefault, equalTo(mappingsWithDefault)); + } + + private String mappingsToString(ToXContent builder, boolean includeDefaults) throws IOException { + ToXContent.Params params = includeDefaults ? + new ToXContent.MapParams(Collections.singletonMap("include_defaults", "true")) : ToXContent.EMPTY_PARAMS; + XContentBuilder x = JsonXContent.contentBuilder(); + x.startObject().startObject("properties"); + builder.toXContent(x, params); + x.endObject().endObject(); + return Strings.toString(x); } } diff --git a/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/mapper/HistogramFieldMapperTests.java b/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/mapper/HistogramFieldMapperTests.java index bd24872ee70..91c7a1024ac 100644 --- a/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/mapper/HistogramFieldMapperTests.java +++ b/x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/mapper/HistogramFieldMapperTests.java @@ -37,7 +37,7 @@ public class HistogramFieldMapperTests extends FieldMapperTestCase unsupportedProperties() { - return org.elasticsearch.common.collect.Set.of("analyzer", "similarity", "doc_values", "store"); + return org.elasticsearch.common.collect.Set.of("analyzer", "similarity", "doc_values", "store", "index"); } public void testParseValue() throws Exception { diff --git a/x-pack/plugin/mapper-constant-keyword/src/main/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapper.java b/x-pack/plugin/mapper-constant-keyword/src/main/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapper.java index b98559e7b53..17a984c4ac8 100644 --- a/x-pack/plugin/mapper-constant-keyword/src/main/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapper.java +++ b/x-pack/plugin/mapper-constant-keyword/src/main/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapper.java @@ -69,6 +69,8 @@ public class ConstantKeywordFieldMapper extends FieldMapper { builder = this; } + // TODO we should ban setting 'index' on constant keyword + public Builder setValue(String value) { this.value = value; return this; diff --git a/x-pack/plugin/mapper-constant-keyword/src/test/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapperTests.java b/x-pack/plugin/mapper-constant-keyword/src/test/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapperTests.java index e8962e9fd51..3337ff40508 100644 --- a/x-pack/plugin/mapper-constant-keyword/src/test/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapperTests.java +++ b/x-pack/plugin/mapper-constant-keyword/src/test/java/org/elasticsearch/xpack/constantkeyword/mapper/ConstantKeywordFieldMapperTests.java @@ -36,7 +36,7 @@ public class ConstantKeywordFieldMapperTests extends FieldMapperTestCase unsupportedProperties() { - return org.elasticsearch.common.collect.Set.of("analyzer", "similarity", "store", "doc_values"); + return org.elasticsearch.common.collect.Set.of("analyzer", "similarity", "store", "doc_values", "index"); } @Override diff --git a/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/mapper/FlatObjectFieldMapper.java b/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/mapper/FlatObjectFieldMapper.java index ff702414b39..3213ddb65ee 100644 --- a/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/mapper/FlatObjectFieldMapper.java +++ b/x-pack/plugin/mapper-flattened/src/main/java/org/elasticsearch/xpack/flattened/mapper/FlatObjectFieldMapper.java @@ -633,7 +633,8 @@ public final class FlatObjectFieldMapper extends DynamicKeyFieldMapper { @Override protected void doXContentBody(XContentBuilder builder, boolean includeDefaults, Params params) throws IOException { super.doXContentBody(builder, includeDefaults, params); - if (includeDefaults || mappedFieldType.isSearchable() && fieldType.indexOptions() != Defaults.FIELD_TYPE.indexOptions()) { + if (fieldType.indexOptions() != IndexOptions.NONE + && (includeDefaults || fieldType.indexOptions() != Defaults.FIELD_TYPE.indexOptions())) { builder.field("index_options", indexOptionToString(fieldType.indexOptions())); } if (includeDefaults || depthLimit != Defaults.DEPTH_LIMIT) { diff --git a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapper.java b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapper.java index 4f604ff943a..b1f4da8c521 100644 --- a/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapper.java +++ b/x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/GeoShapeWithDocValuesFieldMapper.java @@ -9,6 +9,7 @@ package org.elasticsearch.xpack.spatial.index.mapper; import org.apache.lucene.document.FieldType; import org.apache.lucene.document.LatLonShape; import org.apache.lucene.document.ShapeField; +import org.apache.lucene.index.IndexOptions; import org.apache.lucene.index.IndexableField; import org.apache.lucene.util.BytesRef; import org.elasticsearch.Version; @@ -60,13 +61,17 @@ import java.util.Map; */ public class GeoShapeWithDocValuesFieldMapper extends GeoShapeFieldMapper { public static final String CONTENT_TYPE = "geo_shape"; + public static final FieldType FIELD_TYPE = new FieldType(); + static { + FIELD_TYPE.setIndexOptions(IndexOptions.DOCS); + } public static class Builder extends AbstractShapeGeometryFieldMapper.Builder { private boolean docValuesSet = false; public Builder(String name) { - super (name, new FieldType()); + super (name, FIELD_TYPE); this.hasDocValues = true; } diff --git a/x-pack/plugin/vectors/src/test/java/org/elasticsearch/xpack/vectors/mapper/DenseVectorFieldMapperTests.java b/x-pack/plugin/vectors/src/test/java/org/elasticsearch/xpack/vectors/mapper/DenseVectorFieldMapperTests.java index 651bd106d71..727ae287514 100644 --- a/x-pack/plugin/vectors/src/test/java/org/elasticsearch/xpack/vectors/mapper/DenseVectorFieldMapperTests.java +++ b/x-pack/plugin/vectors/src/test/java/org/elasticsearch/xpack/vectors/mapper/DenseVectorFieldMapperTests.java @@ -52,7 +52,7 @@ public class DenseVectorFieldMapperTests extends FieldMapperTestCase unsupportedProperties() { - return org.elasticsearch.common.collect.Set.of("analyzer", "similarity", "doc_values", "store"); + return org.elasticsearch.common.collect.Set.of("analyzer", "similarity", "doc_values", "store", "index"); } @Before diff --git a/x-pack/plugin/vectors/src/test/java/org/elasticsearch/xpack/vectors/mapper/SparseVectorFieldMapperTests.java b/x-pack/plugin/vectors/src/test/java/org/elasticsearch/xpack/vectors/mapper/SparseVectorFieldMapperTests.java index b3a33e984d9..275baf939d3 100644 --- a/x-pack/plugin/vectors/src/test/java/org/elasticsearch/xpack/vectors/mapper/SparseVectorFieldMapperTests.java +++ b/x-pack/plugin/vectors/src/test/java/org/elasticsearch/xpack/vectors/mapper/SparseVectorFieldMapperTests.java @@ -47,7 +47,7 @@ public class SparseVectorFieldMapperTests extends FieldMapperTestCase unsupportedProperties() { - return org.elasticsearch.common.collect.Set.of("analyzer", "similarity", "doc_values", "store"); + return org.elasticsearch.common.collect.Set.of("analyzer", "similarity", "doc_values", "store", "index"); } @Before