Browse Source

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
Ryan Ernst 10 years ago
parent
commit
1c99626b84

+ 3 - 2
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<String, Object> 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<Map.Entry<String, Object>> iterator = node.entrySet().iterator(); iterator.hasNext();) {
                 Map.Entry<String, Object> entry = iterator.next();
                 String fieldName = Strings.toUnderscoreCase(entry.getKey());

+ 11 - 10
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));

+ 4 - 12
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.

+ 1 - 1
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.