Skip to content

Commit 0d8e399

Browse files
committed
Fix MapperService.unmappedType("string") to not raise an error.
A deprecation log will be emitted if you do. This should fix the kibana build.
1 parent e0cde29 commit 0d8e399

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

core/src/main/java/org/elasticsearch/index/mapper/MapperService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,10 @@ public ObjectMapper getObjectMapper(String name) {
530530
* Given a type (eg. long, string, ...), return an anonymous field mapper that can be used for search operations.
531531
*/
532532
public MappedFieldType unmappedFieldType(String type) {
533+
if (type.equals("string")) {
534+
deprecationLogger.deprecated("[unmapped_type:string] should be replaced with [unmapped_type:keyword]");
535+
type = "keyword";
536+
}
533537
MappedFieldType fieldType = unmappedFieldTypes.get(type);
534538
if (fieldType == null) {
535539
final Mapper.TypeParser.ParserContext parserContext = documentMapperParser().parserContext(type);

core/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,17 @@
1919

2020
package org.elasticsearch.index.mapper;
2121

22-
import org.apache.lucene.index.Term;
23-
import org.apache.lucene.queries.TermsQuery;
24-
import org.apache.lucene.search.BooleanClause;
25-
import org.apache.lucene.search.BooleanQuery;
26-
import org.apache.lucene.search.ConstantScoreQuery;
27-
import org.apache.lucene.search.Query;
28-
import org.apache.lucene.search.TermQuery;
29-
import org.apache.lucene.util.BytesRef;
3022
import org.elasticsearch.ExceptionsHelper;
23+
import org.elasticsearch.Version;
24+
import org.elasticsearch.cluster.metadata.IndexMetaData;
3125
import org.elasticsearch.common.compress.CompressedXContent;
32-
import org.elasticsearch.common.lucene.search.Queries;
26+
3327
import org.elasticsearch.common.settings.Settings;
3428
import org.elasticsearch.common.xcontent.XContentFactory;
3529
import org.elasticsearch.index.IndexService;
3630
import org.elasticsearch.index.mapper.MapperService.MergeReason;
37-
import org.elasticsearch.index.mapper.internal.TypeFieldMapper;
31+
import org.elasticsearch.index.mapper.core.KeywordFieldMapper.KeywordFieldType;
32+
import org.elasticsearch.index.mapper.core.LongFieldMapper.LongFieldType;
3833
import org.elasticsearch.test.ESSingleNodeTestCase;
3934
import org.junit.Rule;
4035
import org.junit.rules.ExpectedException;
@@ -48,9 +43,10 @@
4843
import java.util.concurrent.ExecutionException;
4944

5045
import static org.hamcrest.CoreMatchers.containsString;
51-
import static org.hamcrest.CoreMatchers.nullValue;
52-
import static org.hamcrest.Matchers.equalTo;
46+
5347
import static org.hamcrest.Matchers.hasToString;
48+
import static org.hamcrest.Matchers.instanceOf;
49+
5450

5551
public class MapperServiceTests extends ESSingleNodeTestCase {
5652
@Rule
@@ -188,4 +184,13 @@ public void testMappingDepthExceedsLimit() throws Throwable {
188184
() -> indexService1.mapperService().merge("type2", objectMapping, MergeReason.MAPPING_UPDATE, false));
189185
assertThat(e.getMessage(), containsString("Limit of mapping depth [1] in index [test1] has been exceeded"));
190186
}
187+
188+
public void testUnmappedFieldType() {
189+
MapperService mapperService = createIndex("index").mapperService();
190+
assertThat(mapperService.unmappedFieldType("keyword"), instanceOf(KeywordFieldType.class));
191+
assertThat(mapperService.unmappedFieldType("long"), instanceOf(LongFieldType.class));
192+
// back compat
193+
assertThat(mapperService.unmappedFieldType("string"), instanceOf(KeywordFieldType.class));
194+
}
195+
191196
}

0 commit comments

Comments
 (0)