From 0d8e39978121def4a4fa77d1dd6787b7a46843a4 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Fri, 8 Apr 2016 10:08:36 +0200 Subject: [PATCH] Fix `MapperService.unmappedType("string")` to not raise an error. A deprecation log will be emitted if you do. This should fix the kibana build. --- .../index/mapper/MapperService.java | 4 +++ .../index/mapper/MapperServiceTests.java | 29 +++++++++++-------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java b/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java index 4f7fa32e5f6..ea9462071a0 100755 --- a/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -530,6 +530,10 @@ public class MapperService extends AbstractIndexComponent implements Closeable { * Given a type (eg. long, string, ...), return an anonymous field mapper that can be used for search operations. */ public MappedFieldType unmappedFieldType(String type) { + if (type.equals("string")) { + deprecationLogger.deprecated("[unmapped_type:string] should be replaced with [unmapped_type:keyword]"); + type = "keyword"; + } MappedFieldType fieldType = unmappedFieldTypes.get(type); if (fieldType == null) { final Mapper.TypeParser.ParserContext parserContext = documentMapperParser().parserContext(type); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java b/core/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java index a0fc90fe086..3a5de78c496 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java @@ -19,22 +19,17 @@ package org.elasticsearch.index.mapper; -import org.apache.lucene.index.Term; -import org.apache.lucene.queries.TermsQuery; -import org.apache.lucene.search.BooleanClause; -import org.apache.lucene.search.BooleanQuery; -import org.apache.lucene.search.ConstantScoreQuery; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.TermQuery; -import org.apache.lucene.util.BytesRef; import org.elasticsearch.ExceptionsHelper; +import org.elasticsearch.Version; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.compress.CompressedXContent; -import org.elasticsearch.common.lucene.search.Queries; + import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.mapper.MapperService.MergeReason; -import org.elasticsearch.index.mapper.internal.TypeFieldMapper; +import org.elasticsearch.index.mapper.core.KeywordFieldMapper.KeywordFieldType; +import org.elasticsearch.index.mapper.core.LongFieldMapper.LongFieldType; import org.elasticsearch.test.ESSingleNodeTestCase; import org.junit.Rule; import org.junit.rules.ExpectedException; @@ -48,9 +43,10 @@ import java.util.function.Function; import java.util.concurrent.ExecutionException; import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.Matchers.equalTo; + import static org.hamcrest.Matchers.hasToString; +import static org.hamcrest.Matchers.instanceOf; + public class MapperServiceTests extends ESSingleNodeTestCase { @Rule @@ -188,4 +184,13 @@ public class MapperServiceTests extends ESSingleNodeTestCase { () -> indexService1.mapperService().merge("type2", objectMapping, MergeReason.MAPPING_UPDATE, false)); assertThat(e.getMessage(), containsString("Limit of mapping depth [1] in index [test1] has been exceeded")); } + + public void testUnmappedFieldType() { + MapperService mapperService = createIndex("index").mapperService(); + assertThat(mapperService.unmappedFieldType("keyword"), instanceOf(KeywordFieldType.class)); + assertThat(mapperService.unmappedFieldType("long"), instanceOf(LongFieldType.class)); + // back compat + assertThat(mapperService.unmappedFieldType("string"), instanceOf(KeywordFieldType.class)); + } + }