diff --git a/core/src/main/java/org/elasticsearch/index/mapper/internal/IndexFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/internal/IndexFieldMapper.java index 2c506f24a55..3f395a8e0d1 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/internal/IndexFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/internal/IndexFieldMapper.java @@ -102,10 +102,11 @@ public class IndexFieldMapper extends MetadataFieldMapper { @Override public Mapper.Builder parse(String name, Map node, ParserContext parserContext) throws MapperParsingException { Builder builder = new Builder(parserContext.mapperService().fullName(NAME)); - if (parserContext.indexVersionCreated().before(Version.V_2_0_0_beta1)) { - parseField(builder, builder.name, node, parserContext); + if (parserContext.indexVersionCreated().onOrAfter(Version.V_2_0_0_beta1)) { + return builder; } + parseField(builder, builder.name, node, parserContext); for (Iterator> iterator = node.entrySet().iterator(); iterator.hasNext();) { Map.Entry entry = iterator.next(); String fieldName = Strings.toUnderscoreCase(entry.getKey()); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/index/IndexTypeMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/index/IndexTypeMapperTests.java index 3a8accd6a64..ff24061fd03 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/index/IndexTypeMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/index/IndexTypeMapperTests.java @@ -32,12 +32,13 @@ import org.elasticsearch.test.ElasticsearchSingleNodeTest; import static org.hamcrest.Matchers.*; public class IndexTypeMapperTests extends ElasticsearchSingleNodeTest { + private Settings bwcSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_1_4_2.id).build(); - public void testSimpleIndexMapper() throws Exception { + public void testSimpleIndexMapperEnabledBackcompat() throws Exception { String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("_index").field("enabled", true).endObject() .endObject().endObject().string(); - DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping); + DocumentMapper docMapper = createIndex("test", bwcSettings).mapperService().documentMapperParser().parse(mapping); IndexFieldMapper indexMapper = docMapper.indexMapper(); assertThat(indexMapper.enabled(), equalTo(true)); @@ -51,11 +52,11 @@ public class IndexTypeMapperTests extends ElasticsearchSingleNodeTest { assertThat(doc.rootDoc().get("field"), equalTo("value")); } - public void testExplicitDisabledIndexMapper() throws Exception { + public void testExplicitDisabledIndexMapperBackcompat() throws Exception { String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("_index").field("enabled", false).endObject() .endObject().endObject().string(); - DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse(mapping); + DocumentMapper docMapper = createIndex("test", bwcSettings).mapperService().documentMapperParser().parse(mapping); IndexFieldMapper indexMapper = docMapper.rootMapper(IndexFieldMapper.class); assertThat(indexMapper.enabled(), equalTo(false)); @@ -86,11 +87,11 @@ public class IndexTypeMapperTests extends ElasticsearchSingleNodeTest { assertThat(doc.rootDoc().get("field"), equalTo("value")); } - public void testThatMergingFieldMappingAllowsDisabling() throws Exception { + public void testThatMergingFieldMappingAllowsDisablingBackcompat() throws Exception { String mappingWithIndexEnabled = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("_index").field("enabled", true).endObject() .endObject().endObject().string(); - DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser(); + DocumentMapperParser parser = createIndex("test", bwcSettings).mapperService().documentMapperParser(); DocumentMapper mapperEnabled = parser.parse(mappingWithIndexEnabled); @@ -103,11 +104,11 @@ public class IndexTypeMapperTests extends ElasticsearchSingleNodeTest { assertThat(mapperEnabled.IndexFieldMapper().enabled(), is(false)); } - public void testThatDisablingWorksWhenMerging() throws Exception { + public void testThatDisablingWorksWhenMergingBackcompat() throws Exception { String enabledMapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("_index").field("enabled", true).endObject() .endObject().endObject().string(); - DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser(); + DocumentMapperParser parser = createIndex("test", bwcSettings).mapperService().documentMapperParser(); DocumentMapper enabledMapper = parser.parse(enabledMapping); String disabledMapping = XContentFactory.jsonBuilder().startObject().startObject("type") @@ -125,8 +126,8 @@ public class IndexTypeMapperTests extends ElasticsearchSingleNodeTest { .field("enabled", true) .field("store", "yes").endObject() .endObject().endObject().string(); - Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_1_4_2.id).build(); - DocumentMapper docMapper = createIndex("test", indexSettings).mapperService().documentMapperParser().parse(mapping); + + DocumentMapper docMapper = createIndex("test", bwcSettings).mapperService().documentMapperParser().parse(mapping); IndexFieldMapper indexMapper = docMapper.rootMapper(IndexFieldMapper.class); assertThat(indexMapper.enabled(), equalTo(true)); assertThat(indexMapper.fieldType().stored(), equalTo(true)); diff --git a/docs/reference/mapping/fields/index-field.asciidoc b/docs/reference/mapping/fields/index-field.asciidoc index c5db81ba834..0a1928f15ff 100644 --- a/docs/reference/mapping/fields/index-field.asciidoc +++ b/docs/reference/mapping/fields/index-field.asciidoc @@ -1,10 +1,10 @@ [[mapping-index-field]] === `_index` field -The name of the index that contains the document. This field is not indexed -but can be automatically derived from the index itself. - -Its value is accessible in queries, aggregations, scripts, and when sorting: +When performing queries across multiple indexes, it is sometimes desirable +to add query clauses that are associated with documents of only certain +indexes. The `_index` field allows matching on the index a document was +indexed into. Its value is accessible in queries, aggregations, scripts, and when sorting: [source,js] -------------------------- diff --git a/docs/reference/migration/migrate_2_0.asciidoc b/docs/reference/migration/migrate_2_0.asciidoc index d5bda56f1a0..84d60fb0304 100644 --- a/docs/reference/migration/migrate_2_0.asciidoc +++ b/docs/reference/migration/migrate_2_0.asciidoc @@ -290,7 +290,7 @@ to provide special features. They now have limited configuration options. * `_id` configuration can no longer be changed. If you need to sort, use `_uid` instead. * `_type` configuration can no longer be changed. -* `_index` configuration is limited to enabling the field. +* `_index` configuration can no longer be changed. * `_routing` configuration is limited to requiring the field. * `_boost` has been removed. * `_field_names` configuration is limited to disabling the field.