From 1c99626b844dd9103e8ddae7f132557ba3c0c9f6 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Mon, 20 Jul 2015 23:54:35 -0700 Subject: [PATCH] Mappings: Remove ability to configure _index The `_index` field is now a completely virtual field thanks to #12027. It is no longer necessary to index the actual value of the index name. closes #12329 --- .../mapper/internal/IndexFieldMapper.java | 5 +++-- .../mapper/index/IndexTypeMapperTests.java | 21 ++++++++++--------- .../mapping/fields/index-field.asciidoc | 16 ++++---------- docs/reference/migration/migrate_2_0.asciidoc | 2 +- 4 files changed, 19 insertions(+), 25 deletions(-) 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 96a320b9fa5..41cafe8a80e 100644 --- a/docs/reference/mapping/fields/index-field.asciidoc +++ b/docs/reference/mapping/fields/index-field.asciidoc @@ -1,15 +1,7 @@ [[mapping-index-field]] === `_index` -The ability to store in a document the index it belongs to. By default -it is disabled, in order to enable it, the following mapping should be -defined: - -[source,js] --------------------------------------------------- -{ - "tweet" : { - "_index" : { "enabled" : true } - } -} --------------------------------------------------- +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. diff --git a/docs/reference/migration/migrate_2_0.asciidoc b/docs/reference/migration/migrate_2_0.asciidoc index b980d7a8049..7e1e303e330 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.