Deprecate string in favor of text/keyword. #16877

This commit removes the ability to use string fields on indices created on or
after 5.0. Dynamic mappings now generate text fields by default for strings
but there are plans to also add a sub keyword field (in a future PR).

Most of the changes in this commit are just about replacing string with
keyword or text. Some tests have been removed because they existed because of
corner cases of string mappings like setting ignore-above on a text field or
enabling term vectors on a keyword field which are now impossible.

The plan is to remove strings entirely in 6.0.
This commit is contained in:
Adrien Grand 2016-03-01 11:05:42 +01:00
parent f70e5aca50
commit eef19be072
54 changed files with 206 additions and 273 deletions

View File

@ -510,17 +510,17 @@ class DocumentParser implements Closeable {
private static Mapper.Builder<?,?> createBuilderFromFieldType(final ParseContext context, MappedFieldType fieldType, String currentFieldName) {
Mapper.Builder builder = null;
if (fieldType instanceof StringFieldType) {
builder = context.root().findTemplateBuilder(context, currentFieldName, "string");
builder = context.root().findTemplateBuilder(context, currentFieldName, "string", "string");
if (builder == null) {
builder = new StringFieldMapper.Builder(currentFieldName);
}
} else if (fieldType instanceof TextFieldType) {
builder = context.root().findTemplateBuilder(context, currentFieldName, "string");
builder = context.root().findTemplateBuilder(context, currentFieldName, "text", "string");
if (builder == null) {
builder = new TextFieldMapper.Builder(currentFieldName);
}
} else if (fieldType instanceof KeywordFieldType) {
builder = context.root().findTemplateBuilder(context, currentFieldName, "string");
builder = context.root().findTemplateBuilder(context, currentFieldName, "keyword", "string");
if (builder == null) {
builder = new KeywordFieldMapper.Builder(currentFieldName);
}
@ -568,7 +568,7 @@ class DocumentParser implements Closeable {
// we need to do it here so we can handle things like attachment templates, where calling
// text (to see if its a date) causes the binary value to be cleared
{
Mapper.Builder builder = context.root().findTemplateBuilder(context, currentFieldName, "string", null);
Mapper.Builder builder = context.root().findTemplateBuilder(context, currentFieldName, "text", null);
if (builder != null) {
return builder;
}
@ -617,7 +617,7 @@ class DocumentParser implements Closeable {
}
Mapper.Builder builder = context.root().findTemplateBuilder(context, currentFieldName, "string");
if (builder == null) {
builder = new StringFieldMapper.Builder(currentFieldName);
builder = new TextFieldMapper.Builder(currentFieldName);
}
return builder;
} else if (token == XContentParser.Token.VALUE_NUMBER) {

View File

@ -132,6 +132,10 @@ public class StringFieldMapper extends FieldMapper implements AllFieldMapper.Inc
public static class TypeParser implements Mapper.TypeParser {
@Override
public Mapper.Builder parse(String fieldName, Map<String, Object> node, ParserContext parserContext) throws MapperParsingException {
if (parserContext.indexVersionCreated().onOrAfter(Version.V_5_0_0)) {
throw new IllegalArgumentException("The [string] type is removed in 5.0. You should now use either a [text] "
+ "or [keyword] field instead for field [" + fieldName + "]");
}
StringFieldMapper.Builder builder = new StringFieldMapper.Builder(fieldName);
// hack for the fact that string can't just accept true/false for
// the index property and still accepts no/not_analyzed/analyzed
@ -236,6 +240,10 @@ public class StringFieldMapper extends FieldMapper implements AllFieldMapper.Inc
int positionIncrementGap, int ignoreAbove,
Settings indexSettings, MultiFields multiFields, CopyTo copyTo) {
super(simpleName, fieldType, defaultFieldType, indexSettings, multiFields, copyTo);
if (Version.indexCreated(indexSettings).onOrAfter(Version.V_5_0_0)) {
throw new IllegalArgumentException("The [string] type is removed in 5.0. You should now use either a [text] "
+ "or [keyword] field instead for field [" + fieldType.name() + "]");
}
if (fieldType.tokenized() && fieldType.indexOptions() != NONE && fieldType().hasDocValues()) {
throw new MapperParsingException("Field [" + fieldType.name() + "] cannot be analyzed and have doc values");
}

View File

@ -20,8 +20,6 @@
package org.elasticsearch.index.mapper.geo;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.spatial.geopoint.document.GeoPointField;
import org.apache.lucene.spatial.util.GeoHashUtils;
import org.apache.lucene.util.NumericUtils;
import org.elasticsearch.Version;
@ -40,9 +38,8 @@ import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.core.DoubleFieldMapper;
import org.elasticsearch.index.mapper.core.KeywordFieldMapper;
import org.elasticsearch.index.mapper.core.NumberFieldMapper;
import org.elasticsearch.index.mapper.core.StringFieldMapper;
import org.elasticsearch.index.mapper.core.TokenCountFieldMapper;
import org.elasticsearch.index.mapper.object.ArrayValueMapperParser;
import java.io.IOException;
@ -148,7 +145,7 @@ public abstract class BaseGeoPointFieldMapper extends FieldMapper implements Arr
public abstract Y build(BuilderContext context, String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType,
Settings indexSettings, DoubleFieldMapper latMapper, DoubleFieldMapper lonMapper,
StringFieldMapper geoHashMapper, MultiFields multiFields, Explicit<Boolean> ignoreMalformed, CopyTo copyTo);
KeywordFieldMapper geoHashMapper, MultiFields multiFields, Explicit<Boolean> ignoreMalformed, CopyTo copyTo);
public Y build(Mapper.BuilderContext context) {
GeoPointFieldType geoPointFieldType = (GeoPointFieldType)fieldType;
@ -168,11 +165,10 @@ public abstract class BaseGeoPointFieldMapper extends FieldMapper implements Arr
lonMapper = (DoubleFieldMapper) lonMapperBuilder.includeInAll(false).store(fieldType.stored()).docValues(false).build(context);
geoPointFieldType.setLatLonEnabled(latMapper.fieldType(), lonMapper.fieldType());
}
StringFieldMapper geoHashMapper = null;
KeywordFieldMapper geoHashMapper = null;
if (enableGeoHash || enableGeoHashPrefix) {
// TODO: possible also implicitly enable geohash if geohash precision is set
geoHashMapper = new StringFieldMapper.Builder(Names.GEOHASH).index(true).tokenized(false).includeInAll(false).store(fieldType.stored())
.omitNorms(true).indexOptions(IndexOptions.DOCS).build(context);
geoHashMapper = new KeywordFieldMapper.Builder(Names.GEOHASH).index(true).includeInAll(false).store(fieldType.stored()).build(context);
geoPointFieldType.setGeoHashEnabled(geoHashMapper.fieldType(), geoHashPrecision, enableGeoHashPrefix);
}
context.path().remove();
@ -349,12 +345,12 @@ public abstract class BaseGeoPointFieldMapper extends FieldMapper implements Arr
protected DoubleFieldMapper lonMapper;
protected StringFieldMapper geoHashMapper;
protected KeywordFieldMapper geoHashMapper;
protected Explicit<Boolean> ignoreMalformed;
protected BaseGeoPointFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType, Settings indexSettings,
DoubleFieldMapper latMapper, DoubleFieldMapper lonMapper, StringFieldMapper geoHashMapper,
DoubleFieldMapper latMapper, DoubleFieldMapper lonMapper, KeywordFieldMapper geoHashMapper,
MultiFields multiFields, Explicit<Boolean> ignoreMalformed, CopyTo copyTo) {
super(simpleName, fieldType, defaultFieldType, indexSettings, multiFields, copyTo);
this.latMapper = latMapper;
@ -507,7 +503,7 @@ public abstract class BaseGeoPointFieldMapper extends FieldMapper implements Arr
@Override
public FieldMapper updateFieldType(Map<String, MappedFieldType> fullNameToFieldType) {
BaseGeoPointFieldMapper updated = (BaseGeoPointFieldMapper) super.updateFieldType(fullNameToFieldType);
StringFieldMapper geoUpdated = geoHashMapper == null ? null : (StringFieldMapper) geoHashMapper.updateFieldType(fullNameToFieldType);
KeywordFieldMapper geoUpdated = geoHashMapper == null ? null : (KeywordFieldMapper) geoHashMapper.updateFieldType(fullNameToFieldType);
DoubleFieldMapper latUpdated = latMapper == null ? null : (DoubleFieldMapper) latMapper.updateFieldType(fullNameToFieldType);
DoubleFieldMapper lonUpdated = lonMapper == null ? null : (DoubleFieldMapper) lonMapper.updateFieldType(fullNameToFieldType);
if (updated == this

View File

@ -33,7 +33,7 @@ import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.core.DoubleFieldMapper;
import org.elasticsearch.index.mapper.core.StringFieldMapper;
import org.elasticsearch.index.mapper.core.KeywordFieldMapper;
import java.io.IOException;
import java.util.Map;
@ -79,7 +79,7 @@ public class GeoPointFieldMapper extends BaseGeoPointFieldMapper {
@Override
public GeoPointFieldMapper build(BuilderContext context, String simpleName, MappedFieldType fieldType,
MappedFieldType defaultFieldType, Settings indexSettings, DoubleFieldMapper latMapper,
DoubleFieldMapper lonMapper, StringFieldMapper geoHashMapper, MultiFields multiFields, Explicit<Boolean> ignoreMalformed,
DoubleFieldMapper lonMapper, KeywordFieldMapper geoHashMapper, MultiFields multiFields, Explicit<Boolean> ignoreMalformed,
CopyTo copyTo) {
fieldType.setTokenized(false);
if (context.indexCreatedVersion().before(Version.V_2_3_0)) {
@ -110,7 +110,7 @@ public class GeoPointFieldMapper extends BaseGeoPointFieldMapper {
public GeoPointFieldMapper(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType, Settings indexSettings,
DoubleFieldMapper latMapper, DoubleFieldMapper lonMapper,
StringFieldMapper geoHashMapper, MultiFields multiFields, Explicit<Boolean> ignoreMalformed, CopyTo copyTo) {
KeywordFieldMapper geoHashMapper, MultiFields multiFields, Explicit<Boolean> ignoreMalformed, CopyTo copyTo) {
super(simpleName, fieldType, defaultFieldType, indexSettings, latMapper, lonMapper, geoHashMapper, multiFields,
ignoreMalformed, copyTo);
}

View File

@ -24,7 +24,6 @@ import com.carrotsearch.hppc.cursors.ObjectCursor;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.Version;
import org.elasticsearch.common.Explicit;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.geo.GeoDistance;
@ -40,8 +39,8 @@ import org.elasticsearch.index.mapper.Mapper;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.index.mapper.ParseContext;
import org.elasticsearch.index.mapper.core.DoubleFieldMapper;
import org.elasticsearch.index.mapper.core.KeywordFieldMapper;
import org.elasticsearch.index.mapper.core.NumberFieldMapper.CustomNumericDocValuesField;
import org.elasticsearch.index.mapper.core.StringFieldMapper;
import org.elasticsearch.index.mapper.object.ArrayValueMapperParser;
import java.io.IOException;
@ -110,7 +109,7 @@ public class GeoPointFieldMapperLegacy extends BaseGeoPointFieldMapper implement
@Override
public GeoPointFieldMapperLegacy build(BuilderContext context, String simpleName, MappedFieldType fieldType,
MappedFieldType defaultFieldType, Settings indexSettings, DoubleFieldMapper latMapper,
DoubleFieldMapper lonMapper, StringFieldMapper geoHashMapper, MultiFields multiFields, Explicit<Boolean> ignoreMalformed,
DoubleFieldMapper lonMapper, KeywordFieldMapper geoHashMapper, MultiFields multiFields, Explicit<Boolean> ignoreMalformed,
CopyTo copyTo) {
fieldType.setTokenized(false);
setupFieldType(context);
@ -268,7 +267,7 @@ public class GeoPointFieldMapperLegacy extends BaseGeoPointFieldMapper implement
public GeoPointFieldMapperLegacy(String simpleName, MappedFieldType fieldType, MappedFieldType defaultFieldType, Settings indexSettings,
DoubleFieldMapper latMapper, DoubleFieldMapper lonMapper,
StringFieldMapper geoHashMapper, MultiFields multiFields, Explicit<Boolean> ignoreMalformed,
KeywordFieldMapper geoHashMapper, MultiFields multiFields, Explicit<Boolean> ignoreMalformed,
Explicit<Boolean> coerce, CopyTo copyTo) {
super(simpleName, fieldType, defaultFieldType, indexSettings, latMapper, lonMapper, geoHashMapper, multiFields,
ignoreMalformed, copyTo);

View File

@ -235,10 +235,30 @@ public class RootObjectMapper extends ObjectMapper {
return dynamicDateTimeFormatters;
}
public Mapper.Builder findTemplateBuilder(ParseContext context, String name, String dynamicType) {
return findTemplateBuilder(context, name, dynamicType, dynamicType);
public Mapper.Builder findTemplateBuilder(ParseContext context, String name, String matchType) {
final String dynamicType;
switch (matchType) {
case "string":
// string is a corner case since a json string can either map to a
// text or keyword field in elasticsearch. For now we use text when
// unspecified. For other types, the mapping type matches the json
// type so we are fine
dynamicType = "text";
break;
default:
dynamicType = matchType;
break;
}
return findTemplateBuilder(context, name, dynamicType, matchType);
}
/**
* Find a template. Returns {@code null} if no template could be found.
* @param name the field name
* @param dynamicType the field type to give the field if the template does not define one
* @param matchType the type of the field in the json document or null if unknown
* @return a mapper builder, or null if there is no template for such a field
*/
public Mapper.Builder findTemplateBuilder(ParseContext context, String name, String dynamicType, String matchType) {
DynamicTemplate dynamicTemplate = findTemplate(context.path(), name, matchType);
if (dynamicTemplate == null) {

View File

@ -82,7 +82,7 @@ public abstract class AbstractTermVectorsTestCase extends ESIntegTestCase {
public void addToMappings(XContentBuilder mappingsBuilder) throws IOException {
mappingsBuilder.startObject(name);
mappingsBuilder.field("type", "string");
mappingsBuilder.field("type", "text");
String tv_settings;
if (storedPositions && storedOffset && storedPayloads) {
tv_settings = "with_positions_offsets_payloads";

View File

@ -129,7 +129,7 @@ public class SpecificMasterNodesIT extends ESIntegTestCase {
logger.info("--> start data node / non master node");
internalCluster().startNode(settingsBuilder().put(Node.NODE_DATA_SETTING.getKey(), true).put(Node.NODE_MASTER_SETTING.getKey(), false));
assertAcked(prepareCreate("test").addMapping("type1", "{\"type1\" : {\"properties\" : {\"table_a\" : { \"type\" : \"nested\", \"properties\" : {\"field_a\" : { \"type\" : \"string\" },\"field_b\" :{ \"type\" : \"string\" }}}}}}"));
assertAcked(prepareCreate("test").addMapping("type1", "{\"type1\" : {\"properties\" : {\"table_a\" : { \"type\" : \"nested\", \"properties\" : {\"field_a\" : { \"type\" : \"keyword\" },\"field_b\" :{ \"type\" : \"keyword\" }}}}}}"));
client().admin().indices().prepareAliases().addAlias("test", "a_test", QueryBuilders.nestedQuery("table_a", QueryBuilders.termQuery("table_a.field_b", "y"))).get();
}
}

View File

@ -48,7 +48,7 @@ public class CodecTests extends ESSingleNodeTestCase {
public void testAcceptPostingsFormat() throws IOException {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("field").field("type", "string").field("postings_format", Codec.getDefault().postingsFormat().getName()).endObject().endObject()
.startObject("properties").startObject("field").field("type", "keyword").field("postings_format", Codec.getDefault().postingsFormat().getName()).endObject().endObject()
.endObject().endObject().string();
int i = 0;
for (Version v : VersionUtils.allVersions()) {
@ -75,7 +75,7 @@ public class CodecTests extends ESSingleNodeTestCase {
public void testAcceptDocValuesFormat() throws IOException {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("field").field("type", "string").field("doc_values_format", Codec.getDefault().docValuesFormat().getName()).endObject().endObject()
.startObject("properties").startObject("field").field("type", "keyword").field("doc_values_format", Codec.getDefault().docValuesFormat().getName()).endObject().endObject()
.endObject().endObject().string();
int i = 0;
for (Version v : VersionUtils.allVersions()) {

View File

@ -751,7 +751,7 @@ public class GetActionIT extends ESIntegTestCase {
.startObject("field1").field("type", "object").startObject("properties")
.startObject("field2").field("type", "object").startObject("properties")
.startObject("field3").field("type", "object").startObject("properties")
.startObject("field4").field("type", "string").field("store", true)
.startObject("field4").field("type", "text").field("store", true)
.endObject().endObject()
.endObject().endObject()
.endObject().endObject()

View File

@ -135,7 +135,7 @@ public abstract class AbstractFieldDataTestCase extends ESSingleNodeTestCase {
@Before
public void setup() throws Exception {
Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.CURRENT);
Version version = VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.V_2_3_0); // we need 2.x so that fielddata is allowed on string fields
Settings settings = Settings.builder().put("index.fielddata.cache", "none")
.put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
indexService = createIndex("test", settings);

View File

@ -27,15 +27,12 @@ import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.Accountable;
import org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.fielddata.plain.PagedBytesAtomicFieldData;
import org.elasticsearch.index.fielddata.plain.PagedBytesIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedNumericDVIndexFieldData;
import org.elasticsearch.index.fielddata.plain.SortedSetDVOrdinalsIndexFieldData;
import org.elasticsearch.index.mapper.ContentPath;
@ -46,33 +43,38 @@ import org.elasticsearch.index.mapper.core.ByteFieldMapper;
import org.elasticsearch.index.mapper.core.DoubleFieldMapper;
import org.elasticsearch.index.mapper.core.FloatFieldMapper;
import org.elasticsearch.index.mapper.core.IntegerFieldMapper;
import org.elasticsearch.index.mapper.core.KeywordFieldMapper;
import org.elasticsearch.index.mapper.core.LongFieldMapper;
import org.elasticsearch.index.mapper.core.ShortFieldMapper;
import org.elasticsearch.index.mapper.core.StringFieldMapper;
import org.elasticsearch.index.mapper.core.TextFieldMapper;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESSingleNodeTestCase;
import org.elasticsearch.test.IndexSettingsModule;
import org.elasticsearch.test.InternalSettingsPlugin;
import org.elasticsearch.threadpool.ThreadPool;
import java.util.Arrays;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.Set;
import java.util.Collection;
import java.util.concurrent.atomic.AtomicInteger;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf;
public class IndexFieldDataServiceTests extends ESSingleNodeTestCase {
@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return pluginList(InternalSettingsPlugin.class);
}
public void testGetForFieldDefaults() {
final IndexService indexService = createIndex("test");
final IndexFieldDataService ifdService = indexService.fieldData();
final BuilderContext ctx = new BuilderContext(indexService.getIndexSettings().getSettings(), new ContentPath(1));
final MappedFieldType stringMapper = new StringFieldMapper.Builder("string").tokenized(false).build(ctx).fieldType();
final MappedFieldType stringMapper = new KeywordFieldMapper.Builder("string").build(ctx).fieldType();
ifdService.clear();
IndexFieldData<?> fd = ifdService.getForField(stringMapper);
assertTrue(fd instanceof SortedSetDVOrdinalsIndexFieldData);
@ -99,36 +101,6 @@ public class IndexFieldDataServiceTests extends ESSingleNodeTestCase {
assertTrue(fd instanceof SortedNumericDVIndexFieldData);
}
public void testChangeFieldDataFormat() throws Exception {
final IndexService indexService = createIndex("test");
final IndexFieldDataService ifdService = indexService.fieldData();
final BuilderContext ctx = new BuilderContext(indexService.getIndexSettings().getSettings(), new ContentPath(1));
final MappedFieldType mapper1 = new StringFieldMapper.Builder("s").tokenized(false).docValues(true).fieldDataSettings(Settings.builder().put(FieldDataType.FORMAT_KEY, "paged_bytes").build()).build(ctx).fieldType();
final IndexWriter writer = new IndexWriter(new RAMDirectory(), new IndexWriterConfig(new KeywordAnalyzer()));
Document doc = new Document();
doc.add(new StringField("s", "thisisastring", Store.NO));
writer.addDocument(doc);
final IndexReader reader1 = DirectoryReader.open(writer, true);
IndexFieldData<?> ifd = ifdService.getForField(mapper1);
assertThat(ifd, instanceOf(PagedBytesIndexFieldData.class));
Set<LeafReader> oldSegments = Collections.newSetFromMap(new IdentityHashMap<LeafReader, Boolean>());
for (LeafReaderContext arc : reader1.leaves()) {
oldSegments.add(arc.reader());
AtomicFieldData afd = ifd.load(arc);
assertThat(afd, instanceOf(PagedBytesAtomicFieldData.class));
}
// write new segment
writer.addDocument(doc);
final IndexReader reader2 = DirectoryReader.open(writer, true);
final MappedFieldType mapper2 = new StringFieldMapper.Builder("s").tokenized(false).docValues(true).fieldDataSettings(Settings.builder().put(FieldDataType.FORMAT_KEY, "doc_values").build()).build(ctx).fieldType();
ifd = ifdService.getForField(mapper2);
assertThat(ifd, instanceOf(SortedSetDVOrdinalsIndexFieldData.class));
reader1.close();
reader2.close();
writer.close();
writer.getDirectory().close();
}
public void testFieldDataCacheListener() throws Exception {
final IndexService indexService = createIndex("test");
final IndicesService indicesService = getInstanceFromNode(IndicesService.class);
@ -137,7 +109,7 @@ public class IndexFieldDataServiceTests extends ESSingleNodeTestCase {
indicesService.getIndicesFieldDataCache(), indicesService.getCircuitBreakerService(), indexService.mapperService());
final BuilderContext ctx = new BuilderContext(indexService.getIndexSettings().getSettings(), new ContentPath(1));
final MappedFieldType mapper1 = new StringFieldMapper.Builder("s").tokenized(false).docValues(true).fieldDataSettings(Settings.builder().put(FieldDataType.FORMAT_KEY, "paged_bytes").build()).build(ctx).fieldType();
final MappedFieldType mapper1 = new TextFieldMapper.Builder("s").build(ctx).fieldType();
final IndexWriter writer = new IndexWriter(new RAMDirectory(), new IndexWriterConfig(new KeywordAnalyzer()));
Document doc = new Document();
doc.add(new StringField("s", "thisisastring", Store.NO));

View File

@ -242,7 +242,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
// original mapping not modified
assertEquals(mapping, serialize(mapper));
// but we have an update
assertEquals("{\"type\":{\"properties\":{\"foo\":{\"type\":\"string\"}}}}", serialize(update));
assertEquals("{\"type\":{\"properties\":{\"foo\":{\"type\":\"text\"}}}}", serialize(update));
}
public void testIncremental() throws Exception {
@ -264,7 +264,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
// but we have an update
assertEquals(XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties")
// foo is NOT in the update
.startObject("bar").field("type", "string").endObject()
.startObject("bar").field("type", "text").endObject()
.endObject().endObject().string(), serialize(update));
}
@ -284,8 +284,8 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
assertEquals(mapping, serialize(mapper));
// but we have an update
assertEquals(XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties")
.startObject("bar").field("type", "string").endObject()
.startObject("foo").field("type", "string").endObject()
.startObject("bar").field("type", "text").endObject()
.startObject("foo").field("type", "text").endObject()
.endObject().endObject().string(), serialize(update));
}
@ -305,7 +305,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
assertEquals(mapping, serialize(mapper));
// but we have an update
assertEquals(XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties")
.startObject("foo").startObject("properties").startObject("bar").startObject("properties").startObject("baz").field("type", "string").endObject().endObject().endObject().endObject().endObject()
.startObject("foo").startObject("properties").startObject("bar").startObject("properties").startObject("baz").field("type", "text").endObject().endObject().endObject().endObject().endObject()
.endObject().endObject().endObject().string(), serialize(update));
}
@ -325,7 +325,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
assertEquals(mapping, serialize(mapper));
// but we have an update
assertEquals(XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties")
.startObject("foo").field("type", "string").endObject()
.startObject("foo").field("type", "text").endObject()
.endObject().endObject().endObject().string(), serialize(update));
}
@ -345,7 +345,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
assertEquals(mapping, serialize(mapper));
// but we have an update
assertEquals(XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties")
.startObject("foo").startObject("properties").startObject("bar").startObject("properties").startObject("baz").field("type", "string").endObject().endObject().endObject().endObject().endObject()
.startObject("foo").startObject("properties").startObject("bar").startObject("properties").startObject("baz").field("type", "text").endObject().endObject().endObject().endObject().endObject()
.endObject().endObject().endObject().string(), serialize(update));
}
@ -366,7 +366,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase {
assertEquals(mapping, serialize(mapper));
assertEquals(XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties")
.startObject("foo").startObject("properties")
.startObject("bar").field("type", "string").endObject()
.startObject("bar").field("type", "text").endObject()
.startObject("baz").field("type", "long").endObject()
.endObject().endObject()
.endObject().endObject().endObject().string(), serialize(update));

View File

@ -112,7 +112,7 @@ public class TokenCountFieldMapperIntegrationIT extends ESIntegTestCase {
.startObject("test")
.startObject("properties")
.startObject("foo")
.field("type", "string")
.field("type", "text")
.field("store", storeCountedFields)
.field("analyzer", "simple")
.startObject("fields")

View File

@ -27,7 +27,6 @@ import org.apache.lucene.search.NumericRangeQuery;
import org.apache.lucene.util.Constants;
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.compress.CompressedXContent;
@ -48,11 +47,10 @@ import org.elasticsearch.index.mapper.ParseContext.Document;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.core.DateFieldMapper;
import org.elasticsearch.index.mapper.core.LongFieldMapper;
import org.elasticsearch.index.mapper.core.StringFieldMapper;
import org.elasticsearch.index.mapper.core.TextFieldMapper;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.test.ESSingleNodeTestCase;
import org.elasticsearch.test.TestSearchContext;
import org.elasticsearch.test.VersionUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.junit.Before;
@ -106,11 +104,11 @@ public class SimpleDateMappingTests extends ESSingleNodeTestCase {
assertThat(fieldMapper, instanceOf(DateFieldMapper.class));
fieldMapper = defaultMapper.mappers().smartNameFieldMapper("wrong_date1");
assertThat(fieldMapper, instanceOf(StringFieldMapper.class));
assertThat(fieldMapper, instanceOf(TextFieldMapper.class));
fieldMapper = defaultMapper.mappers().smartNameFieldMapper("wrong_date2");
assertThat(fieldMapper, instanceOf(StringFieldMapper.class));
assertThat(fieldMapper, instanceOf(TextFieldMapper.class));
fieldMapper = defaultMapper.mappers().smartNameFieldMapper("wrong_date3");
assertThat(fieldMapper, instanceOf(StringFieldMapper.class));
assertThat(fieldMapper, instanceOf(TextFieldMapper.class));
}
public void testParseLocal() {

View File

@ -45,7 +45,7 @@ public class SimpleDynamicTemplatesTests extends ESSingleNodeTestCase {
XContentBuilder builder = JsonXContent.contentBuilder();
builder.startObject().startObject("person").startArray("dynamic_templates").startObject().startObject("test")
.field("match_mapping_type", "string")
.startObject("mapping").field("index", "no").endObject()
.startObject("mapping").field("index", false).endObject()
.endObject().endObject().endArray().endObject().endObject();
IndexService index = createIndex("test");
client().admin().indices().preparePutMapping("test").setType("person").setSource(builder.string()).get();

View File

@ -140,7 +140,7 @@ public class MultiFieldTests extends ESSingleNodeTestCase {
IndexService indexService = createIndex("test");
DocumentMapper builderDocMapper = new DocumentMapper.Builder(new RootObjectMapper.Builder("person").add(
new StringFieldMapper.Builder("name").store(true)
new TextFieldMapper.Builder("name").store(true)
.addMultiField(new TextFieldMapper.Builder("indexed").index(true).tokenized(true))
.addMultiField(new TextFieldMapper.Builder("not_indexed").index(false).store(true))
), indexService.mapperService()).build(indexService.mapperService());

View File

@ -35,7 +35,7 @@ import static org.hamcrest.Matchers.equalTo;
public class NullValueTests extends ESSingleNodeTestCase {
public void testNullNullValue() throws Exception {
IndexService indexService = createIndex("test", Settings.settingsBuilder().build());
String[] typesToTest = {"integer", "long", "double", "float", "short", "date", "ip", "string", "boolean", "byte"};
String[] typesToTest = {"integer", "long", "double", "float", "short", "date", "ip", "keyword", "boolean", "byte"};
for (String type : typesToTest) {
String mapping = XContentFactory.jsonBuilder()

View File

@ -40,7 +40,7 @@ import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.core.DoubleFieldMapper;
import org.elasticsearch.index.mapper.core.LongFieldMapper;
import org.elasticsearch.index.mapper.core.NumberFieldMapper;
import org.elasticsearch.index.mapper.core.StringFieldMapper;
import org.elasticsearch.index.mapper.core.TextFieldMapper;
import org.elasticsearch.index.mapper.string.SimpleStringMappingTests;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESSingleNodeTestCase;
@ -111,10 +111,10 @@ public class SimpleNumericTests extends ESSingleNodeTestCase {
defaultMapper = index.mapperService().documentMapper("type");
FieldMapper mapper = defaultMapper.mappers().smartNameFieldMapper("s_long");
assertThat(mapper, instanceOf(StringFieldMapper.class));
assertThat(mapper, instanceOf(TextFieldMapper.class));
mapper = defaultMapper.mappers().smartNameFieldMapper("s_double");
assertThat(mapper, instanceOf(StringFieldMapper.class));
assertThat(mapper, instanceOf(TextFieldMapper.class));
}
public void testIgnoreMalformedOption() throws Exception {

View File

@ -47,7 +47,6 @@ import org.elasticsearch.index.mapper.core.StringFieldMapper.Builder;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESSingleNodeTestCase;
import org.elasticsearch.test.InternalSettingsPlugin;
import org.elasticsearch.test.VersionUtils;
import org.junit.Before;
import java.io.IOException;
@ -75,7 +74,9 @@ public class SimpleStringMappingTests extends ESSingleNodeTestCase {
@Before
public void before() {
indexService = createIndex("test");
indexService = createIndex("test",
// we need 2.x since string is deprecated in 5.0
Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_2_3_0).build());
parser = indexService.mapperService().documentMapperParser();
}

View File

@ -20,14 +20,20 @@
package org.elasticsearch.index.mapper.string;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.Version;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESSingleNodeTestCase;
import org.elasticsearch.test.InternalSettingsPlugin;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import static org.elasticsearch.index.query.QueryBuilders.matchPhraseQuery;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
@ -38,6 +44,12 @@ import static org.hamcrest.Matchers.containsString;
* expected in queries.
*/
public class StringFieldMapperPositionIncrementGapTests extends ESSingleNodeTestCase {
@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return pluginList(InternalSettingsPlugin.class);
}
/**
* The default position_increment_gap should be large enough that most
* "sensible" queries phrase slops won't match across values.
@ -106,11 +118,12 @@ public class StringFieldMapperPositionIncrementGapTests extends ESSingleNodeTest
* strange but not worth breaking some thought.
*/
public void testDefaultDefaultsToAnalyzer() throws IOException {
XContentBuilder settings = XContentFactory.jsonBuilder().startObject().startObject("analysis").startObject("analyzer")
.startObject("gappy");
settings.field("type", "custom");
settings.field("tokenizer", "standard");
settings.field("position_increment_gap", 2);
Settings settings = Settings.builder()
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_2_3_0)
.put("analysis.analyzer.gappy.type", "custom")
.put("analysis.analyzer.gappy.tokenizer", "standard")
.put("analysis.analyzer.gappy.position_increment_gap", "2")
.build();
setupAnalyzer(settings, "gappy");
testGap(client(), "test", "test", 2);
}
@ -123,7 +136,10 @@ public class StringFieldMapperPositionIncrementGapTests extends ESSingleNodeTest
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("properties").startObject("string");
mapping.field("type", "string");
mapping.field("position_increment_gap", positionIncrementGap);
client().admin().indices().prepareCreate("test").addMapping("test", mapping).get();
client().admin().indices().prepareCreate("test")
.setSettings(Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_2_3_0).build())
.addMapping("test", mapping)
.get();
}
/**
@ -131,11 +147,14 @@ public class StringFieldMapperPositionIncrementGapTests extends ESSingleNodeTest
* named "string" that uses the specified analyzer and default
* position_increment_gap.
*/
private void setupAnalyzer(XContentBuilder settings, String analyzer) throws IOException {
private void setupAnalyzer(Settings settings, String analyzer) throws IOException {
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("properties").startObject("string");
mapping.field("type", "string");
mapping.field("analyzer", analyzer);
client().admin().indices().prepareCreate("test").addMapping("test", mapping).setSettings(settings).get();
client().admin().indices().prepareCreate("test")
.addMapping("test", mapping)
.setSettings(settings)
.get();
}
private static void testGap(Client client, String indexName, String type, int positionIncrementGap) throws IOException {

View File

@ -54,10 +54,10 @@ public class MultiMatchQueryTests extends ESSingleNodeTestCase {
" \"name\":{\n" +
" \"properties\":{\n" +
" \"first\": {\n" +
" \"type\":\"string\"\n" +
" \"type\":\"text\"\n" +
" }," +
" \"last\": {\n" +
" \"type\":\"string\"\n" +
" \"type\":\"text\"\n" +
" }" +
" }" +
" }\n" +

View File

@ -44,8 +44,8 @@ public class ConcurrentDynamicTemplateIT extends ESIntegTestCase {
final String fieldName = "field";
final String mapping = "{ \"" + mappingType + "\": {" +
"\"dynamic_templates\": ["
+ "{ \"" + fieldName + "\": {" + "\"path_match\": \"*\"," + "\"mapping\": {" + "\"type\": \"string\"," + "\"store\": true,"
+ "\"index\": \"analyzed\", \"analyzer\": \"whitespace\" } } } ] } }";
+ "{ \"" + fieldName + "\": {" + "\"path_match\": \"*\"," + "\"mapping\": {" + "\"type\": \"text\"," + "\"store\": true,"
+ "\"analyzer\": \"whitespace\" } } } ] } }";
// The 'fieldNames' array is used to help with retrieval of index terms
// after testing

View File

@ -100,7 +100,7 @@ public class UpdateMappingIntegrationIT extends ESIntegTestCase {
settingsBuilder()
.put("index.number_of_shards", 1)
.put("index.number_of_replicas", 0)
).addMapping("doc", "{\"doc\":{\"properties\":{\"body\":{\"type\":\"string\"}}}}")
).addMapping("doc", "{\"doc\":{\"properties\":{\"body\":{\"type\":\"text\"}}}}")
.execute().actionGet();
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
@ -112,7 +112,7 @@ public class UpdateMappingIntegrationIT extends ESIntegTestCase {
GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("test").execute().actionGet();
assertThat(getMappingsResponse.mappings().get("test").get("doc").source().toString(),
equalTo("{\"doc\":{\"properties\":{\"body\":{\"type\":\"string\"},\"date\":{\"type\":\"integer\"}}}}"));
equalTo("{\"doc\":{\"properties\":{\"body\":{\"type\":\"text\"},\"date\":{\"type\":\"integer\"}}}}"));
}
public void testUpdateMappingWithoutTypeMultiObjects() throws Exception {
@ -141,7 +141,7 @@ public class UpdateMappingIntegrationIT extends ESIntegTestCase {
settingsBuilder()
.put("index.number_of_shards", 2)
.put("index.number_of_replicas", 0)
).addMapping("type", "{\"type\":{\"properties\":{\"body\":{\"type\":\"string\"}}}}")
).addMapping("type", "{\"type\":{\"properties\":{\"body\":{\"type\":\"text\"}}}}")
.execute().actionGet();
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
@ -150,17 +150,17 @@ public class UpdateMappingIntegrationIT extends ESIntegTestCase {
.setSource("{\"type\":{\"properties\":{\"body\":{\"type\":\"integer\"}}}}").execute().actionGet();
fail("Expected MergeMappingException");
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), containsString("mapper [body] of different type, current_type [string], merged_type [integer]"));
assertThat(e.getMessage(), containsString("mapper [body] of different type, current_type [text], merged_type [integer]"));
}
}
public void testUpdateMappingWithNormsConflicts() throws Exception {
client().admin().indices().prepareCreate("test")
.addMapping("type", "{\"type\":{\"properties\":{\"body\":{\"type\":\"string\", \"norms\": { \"enabled\": false }}}}}")
.addMapping("type", "{\"type\":{\"properties\":{\"body\":{\"type\":\"text\", \"norms\": { \"enabled\": false }}}}}")
.execute().actionGet();
try {
client().admin().indices().preparePutMapping("test").setType("type")
.setSource("{\"type\":{\"properties\":{\"body\":{\"type\":\"string\", \"norms\": { \"enabled\": true }}}}}").execute()
.setSource("{\"type\":{\"properties\":{\"body\":{\"type\":\"text\", \"norms\": { \"enabled\": true }}}}}").execute()
.actionGet();
fail("Expected MergeMappingException");
} catch (IllegalArgumentException e) {
@ -177,12 +177,12 @@ public class UpdateMappingIntegrationIT extends ESIntegTestCase {
settingsBuilder()
.put("index.number_of_shards", 2)
.put("index.number_of_replicas", 0)
).addMapping("type", "{\"type\":{\"properties\":{\"body\":{\"type\":\"string\"}}}}")
).addMapping("type", "{\"type\":{\"properties\":{\"body\":{\"type\":\"text\"}}}}")
.execute().actionGet();
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping("test").setType("type")
.setSource("{\"type\":{\"properties\":{\"body\":{\"type\":\"string\"}}}}")
.setSource("{\"type\":{\"properties\":{\"body\":{\"type\":\"text\"}}}}")
.execute().actionGet();
//no changes, we return

View File

@ -148,7 +148,7 @@ public class CircuitBreakerServiceIT extends ESIntegTestCase {
// Create an index where the mappings have a field data filter
assertAcked(prepareCreate("ramtest").setSource("{\"mappings\": {\"type\": {\"properties\": {\"test\": " +
"{\"type\": \"string\",\"fielddata\": {\"filter\": {\"regex\": {\"pattern\": \"^value.*\"}}}}}}}}"));
"{\"type\": \"text\",\"fielddata\": {\"filter\": {\"regex\": {\"pattern\": \"^value.*\"}}}}}}}}"));
ensureGreen("ramtest");

View File

@ -749,7 +749,7 @@ public class IndexStatsIT extends ESIntegTestCase {
assertAcked(prepareCreate("test1")
.addMapping(
"bar",
"{ \"properties\": { \"bar\": { \"type\": \"string\", \"fields\": { \"completion\": { \"type\": \"completion\" }}},\"baz\": { \"type\": \"string\", \"fields\": { \"completion\": { \"type\": \"completion\" }}}}}"));
"{ \"properties\": { \"bar\": { \"type\": \"text\", \"fields\": { \"completion\": { \"type\": \"completion\" }}},\"baz\": { \"type\": \"text\", \"fields\": { \"completion\": { \"type\": \"completion\" }}}}}"));
ensureGreen();
client().prepareIndex("test1", "bar", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}").execute().actionGet();

View File

@ -345,7 +345,7 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase {
client().admin().indices().preparePutTemplate("template_with_aliases")
.setTemplate("te*")
.addMapping("type1", "{\"type1\" : {\"properties\" : {\"value\" : {\"type\" : \"string\"}}}}")
.addMapping("type1", "{\"type1\" : {\"properties\" : {\"value\" : {\"type\" : \"text\"}}}}")
.addAlias(new Alias("simple_alias"))
.addAlias(new Alias("templated_alias-{index}"))
.addAlias(new Alias("filtered_alias").filter("{\"type\":{\"value\":\"type2\"}}"))

View File

@ -1683,10 +1683,10 @@ public class PercolatorIT extends ESIntegTestCase {
String mapping = "{\n" +
" \"doc\": {\n" +
" \"properties\": {\n" +
" \"name\": {\"type\":\"string\"},\n" +
" \"name\": {\"type\":\"text\"},\n" +
" \"persons\": {\n" +
" \"type\": \"nested\"\n," +
" \"properties\" : {\"foo\" : {\"type\" : \"string\"}}" +
" \"properties\" : {\"foo\" : {\"type\" : \"text\"}}" +
" }\n" +
" }\n" +
" }\n" +

View File

@ -61,12 +61,12 @@ public class DiversifiedSamplerIT extends ESIntegTestCase {
@Override
public void setupSuiteScopeCluster() throws Exception {
assertAcked(prepareCreate("test").setSettings(SETTING_NUMBER_OF_SHARDS, NUM_SHARDS, SETTING_NUMBER_OF_REPLICAS, 0).addMapping(
"book", "author", "type=string,index=not_analyzed", "name", "type=string,index=analyzed", "genre",
"type=string,index=not_analyzed", "price", "type=float"));
"book", "author", "type=keyword", "name", "type=keyword", "genre",
"type=keyword", "price", "type=float"));
createIndex("idx_unmapped");
// idx_unmapped_author is same as main index but missing author field
assertAcked(prepareCreate("idx_unmapped_author").setSettings(SETTING_NUMBER_OF_SHARDS, NUM_SHARDS, SETTING_NUMBER_OF_REPLICAS, 0)
.addMapping("book", "name", "type=string,index=analyzed", "genre", "type=string,index=not_analyzed", "price",
.addMapping("book", "name", "type=keyword", "genre", "type=keyword", "price",
"type=float"));
ensureGreen();

View File

@ -94,7 +94,7 @@ public class SignificantTermsSignificanceScoreIT extends ESIntegTestCase {
}
public void testPlugin() throws Exception {
String type = randomBoolean() ? "string" : "long";
String type = randomBoolean() ? "text" : "long";
String settings = "{\"index.number_of_shards\": 1, \"index.number_of_replicas\": 0}";
SharedSignificantTermsTestMethods.index01Docs(type, settings, this);
SearchResponse response = client().prepareSearch(INDEX_NAME).setTypes(DOC_TYPE)
@ -257,7 +257,7 @@ public class SignificantTermsSignificanceScoreIT extends ESIntegTestCase {
}
public void testXContentResponse() throws Exception {
String type = randomBoolean() ? "string" : "long";
String type = randomBoolean() ? "text" : "long";
String settings = "{\"index.number_of_shards\": 1, \"index.number_of_replicas\": 0}";
SharedSignificantTermsTestMethods.index01Docs(type, settings, this);
SearchResponse response = client().prepareSearch(INDEX_NAME).setTypes(DOC_TYPE)
@ -333,7 +333,7 @@ public class SignificantTermsSignificanceScoreIT extends ESIntegTestCase {
}
public void testBackgroundVsSeparateSet() throws Exception {
String type = randomBoolean() ? "string" : "long";
String type = randomBoolean() ? "text" : "long";
String settings = "{\"index.number_of_shards\": 1, \"index.number_of_replicas\": 0}";
SharedSignificantTermsTestMethods.index01Docs(type, settings, this);
testBackgroundVsSeparateSet(new MutualInformation(true, true), new MutualInformation(true, false));
@ -460,7 +460,7 @@ public class SignificantTermsSignificanceScoreIT extends ESIntegTestCase {
}
public void testScriptScore() throws ExecutionException, InterruptedException, IOException {
indexRandomFrequencies01(randomBoolean() ? "string" : "long");
indexRandomFrequencies01(randomBoolean() ? "text" : "long");
ScriptHeuristic scriptHeuristic = getScriptSignificanceHeuristic();
ensureYellow();
SearchResponse response = client().prepareSearch(INDEX_NAME)

View File

@ -51,7 +51,7 @@ public class TermsShardMinDocCountIT extends ESIntegTestCase {
// see https://github.com/elasticsearch/elasticsearch/issues/5998
public void testShardMinDocCountSignificantTermsTest() throws Exception {
String termtype = "string";
String termtype = "text";
if (randomBoolean()) {
termtype = "long";
}
@ -109,7 +109,7 @@ public class TermsShardMinDocCountIT extends ESIntegTestCase {
// see https://github.com/elasticsearch/elasticsearch/issues/5998
public void testShardMinDocCountTermsTest() throws Exception {
final String [] termTypes = {"string", "long", "integer", "float", "double"};
final String [] termTypes = {"text", "long", "integer", "float", "double"};
String termtype = termTypes[randomInt(termTypes.length - 1)];
assertAcked(prepareCreate(index).setSettings(SETTING_NUMBER_OF_SHARDS, 1, SETTING_NUMBER_OF_REPLICAS, 0).addMapping(type, "{\"properties\":{\"text\": {\"type\": \"" + termtype + "\"}}}"));

View File

@ -1078,7 +1078,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
// Issue #3818
public void testHasChildQueryOnlyReturnsSingleChildType() {
assertAcked(prepareCreate("grandissue")
.addMapping("grandparent", "name", "type=string")
.addMapping("grandparent", "name", "type=text")
.addMapping("parent", "_parent", "type=grandparent")
.addMapping("child_type_one", "_parent", "type=parent")
.addMapping("child_type_two", "_parent", "type=parent"));

View File

@ -638,7 +638,7 @@ public class DecayFunctionScoreIT extends ESIntegTestCase {
public void testParsingExceptionIfFieldDoesNotExist() throws Exception {
assertAcked(prepareCreate("test").addMapping(
"type",
jsonBuilder().startObject().startObject("type").startObject("properties").startObject("test").field("type", "string")
jsonBuilder().startObject().startObject("type").startObject("properties").startObject("test").field("type", "text")
.endObject().startObject("geo").field("type", "geo_point").endObject().endObject().endObject().endObject()));
ensureYellow();
int numDocs = 2;

View File

@ -113,55 +113,6 @@ public class HighlighterSearchIT extends ESIntegTestCase {
assertHighlight(search, 0, "text", 0, equalTo("<em>text</em>"));
}
public void testPlainHighlighterWithLongUnanalyzedStringTerm() throws IOException {
XContentBuilder mappings = jsonBuilder();
mappings.startObject();
mappings.startObject("type")
.startObject("properties")
.startObject("long_text")
.field("type", "string")
.field("analyzer", "keyword")
.field("index_options", "offsets")
.field("term_vector", "with_positions_offsets")
.field("ignore_above", 1)
.endObject()
.startObject("text")
.field("type", "text")
.field("analyzer", "keyword")
.field("index_options", "offsets")
.field("term_vector", "with_positions_offsets")
.endObject()
.endObject()
.endObject();
mappings.endObject();
assertAcked(prepareCreate("test")
.addMapping("type", mappings));
ensureYellow();
// crate a term that is larger than the allowed 32766, index it and then try highlight on it
// the search request should still succeed
StringBuilder builder = new StringBuilder();
for (int i = 0; i < 32767; i++) {
builder.append('a');
}
client().prepareIndex("test", "type", "1")
.setSource(jsonBuilder().startObject().field("long_text", builder.toString()).field("text", "text").endObject())
.get();
refresh();
String highlighter = randomFrom("plain", "postings", "fvh");
SearchResponse search = client().prepareSearch().setQuery(constantScoreQuery(matchQuery("text", "text")))
.highlighter(new HighlightBuilder().field(new Field("*").highlighterType(highlighter))).get();
assertHighlight(search, 0, "text", 0, equalTo("<em>text</em>"));
search = client().prepareSearch().setQuery(constantScoreQuery(matchQuery("text", "text")))
.highlighter(new HighlightBuilder().field(new Field("long_text").highlighterType(highlighter))).get();
assertNoFailures(search);
assertThat(search.getHits().getAt(0).getHighlightFields().size(), equalTo(0));
search = client().prepareSearch().setQuery(prefixQuery("text", "te"))
.highlighter(new HighlightBuilder().field(new Field("long_text").highlighterType(highlighter))).get();
assertNoFailures(search);
assertThat(search.getHits().getAt(0).getHighlightFields().size(), equalTo(0));
}
public void testHighlightingWhenFieldsAreNotStoredThereIsNoSource() throws IOException {
XContentBuilder mappings = jsonBuilder();
mappings.startObject();

View File

@ -180,41 +180,6 @@ public class FieldSortIT extends ESIntegTestCase {
}
public void testIssue6639() throws ExecutionException, InterruptedException {
assertAcked(prepareCreate("$index")
.addMapping(
"$type",
"{\"$type\": "
+ " {\"properties\": "
+ " {\"grantee\": "
+ " { \"index\": \"not_analyzed\", "
+ " \"term_vector\": \"with_positions_offsets\", "
+ " \"type\": \"string\", "
+ " \"analyzer\": \"snowball\", "
+ " \"boost\": 1.0, "
+ " \"store\": true}}}}"));
indexRandom(true,
client().prepareIndex(
"$index",
"$type",
"data.activity.5").setSource("{\"django_ct\": \"data.activity\", \"grantee\": \"Grantee 1\"}"),
client().prepareIndex(
"$index",
"$type",
"data.activity.6").setSource("{\"django_ct\": \"data.activity\", \"grantee\": \"Grantee 2\"}"));
ensureYellow();
SearchResponse searchResponse = client().prepareSearch()
.setQuery(matchAllQuery())
.addSort("grantee", SortOrder.ASC)
.execute().actionGet();
assertOrderedSearchHits(searchResponse, "data.activity.5", "data.activity.6");
searchResponse = client().prepareSearch()
.setQuery(matchAllQuery())
.addSort("grantee", SortOrder.DESC)
.execute().actionGet();
assertOrderedSearchHits(searchResponse, "data.activity.6", "data.activity.5");
}
public void testTrackScores() throws Exception {
createIndex("test");
ensureGreen();
@ -928,7 +893,7 @@ public class FieldSortIT extends ESIntegTestCase {
SearchResponse searchResponse = client().prepareSearch()
.setQuery(matchAllQuery())
.addSort(SortBuilders.fieldSort("kkk").unmappedType("string"))
.addSort(SortBuilders.fieldSort("kkk").unmappedType("keyword"))
.execute().actionGet();
assertNoFailures(searchResponse);
}

View File

@ -280,7 +280,7 @@ public class GeoDistanceSortBuilderIT extends ESIntegTestCase {
public void testCrossIndexIgnoreUnmapped() throws Exception {
assertAcked(prepareCreate("test1").addMapping(
"type", "str_field1", "type=text",
"type", "str_field1", "type=keyword",
"long_field", "type=long",
"double_field", "type=double").get());
assertAcked(prepareCreate("test2").get());
@ -292,8 +292,8 @@ public class GeoDistanceSortBuilderIT extends ESIntegTestCase {
ensureYellow("test1", "test2");
SearchResponse resp = client().prepareSearch("test1", "test2")
.addSort(fieldSort("str_field").order(SortOrder.ASC).unmappedType("string"))
.addSort(fieldSort("str_field2").order(SortOrder.DESC).unmappedType("string")).get();
.addSort(fieldSort("str_field").order(SortOrder.ASC).unmappedType("keyword"))
.addSort(fieldSort("str_field2").order(SortOrder.DESC).unmappedType("keyword")).get();
assertSortValues(resp,
new Object[] {new Text("bcd"), null},

View File

@ -48,7 +48,7 @@ public class SharedSignificantTermsTestMethods {
public static final String CLASS_FIELD = "class";
public static void aggregateAndCheckFromSeveralShards(ESIntegTestCase testCase) throws ExecutionException, InterruptedException {
String type = ESTestCase.randomBoolean() ? "string" : "long";
String type = ESTestCase.randomBoolean() ? "text" : "long";
String settings = "{\"index.number_of_shards\": 5, \"index.number_of_replicas\": 0}";
index01Docs(type, settings, testCase);
testCase.ensureGreen();

View File

@ -6,12 +6,12 @@
"match":"multi*",
"mapping":{
"type":"{dynamic_type}",
"index":"analyzed",
"index":true,
"store":true,
"fields":{
"org":{
"type":"{dynamic_type}",
"index":"not_analyzed",
"type":"keyword",
"index":true,
"store":true
}
}

View File

@ -69,10 +69,10 @@ public class CardinalityTests extends ESIntegTestCase {
prepareCreate("idx").addMapping("type",
jsonBuilder().startObject().startObject("type").startObject("properties")
.startObject("str_value")
.field("type", "string")
.field("type", "keyword")
.endObject()
.startObject("str_values")
.field("type", "string")
.field("type", "keyword")
.endObject()
.startObject("l_value")
.field("type", "long")

View File

@ -136,7 +136,7 @@ public class IndexLookupTests extends ESIntegTestCase {
expectedEndOffsetsArray.put("3", ends3);
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
.startObject("int_payload_field").field("type", "string").field("index_options", "offsets")
.startObject("int_payload_field").field("type", "text").field("index_options", "offsets")
.field("analyzer", "payload_int").endObject().endObject().endObject().endObject();
assertAcked(prepareCreate("test").addMapping("type1", mapping).setSettings(
Settings.settingsBuilder()
@ -399,10 +399,10 @@ public class IndexLookupTests extends ESIntegTestCase {
public void testAllExceptPosAndOffset() throws Exception {
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
.startObject("float_payload_field").field("type", "string").field("index_options", "offsets").field("term_vector", "no")
.field("analyzer", "payload_float").endObject().startObject("string_payload_field").field("type", "string")
.startObject("float_payload_field").field("type", "text").field("index_options", "offsets").field("term_vector", "no")
.field("analyzer", "payload_float").endObject().startObject("string_payload_field").field("type", "text")
.field("index_options", "offsets").field("term_vector", "no").field("analyzer", "payload_string").endObject()
.startObject("int_payload_field").field("type", "string").field("index_options", "offsets")
.startObject("int_payload_field").field("type", "text").field("index_options", "offsets")
.field("analyzer", "payload_int").endObject().endObject().endObject().endObject();
assertAcked(prepareCreate("test").addMapping("type1", mapping).setSettings(
Settings.settingsBuilder()

View File

@ -552,7 +552,7 @@ public class IndicesRequestTests extends ESIntegTestCase {
public void testPutMapping() {
interceptTransportActions(PutMappingAction.NAME);
PutMappingRequest putMappingRequest = new PutMappingRequest(randomUniqueIndicesOrAliases()).type("type").source("field", "type=string");
PutMappingRequest putMappingRequest = new PutMappingRequest(randomUniqueIndicesOrAliases()).type("type").source("field", "type=text");
internalCluster().clientNodeClient().admin().indices().putMapping(putMappingRequest).actionGet();
clearInterceptedActions();

View File

@ -123,7 +123,7 @@ public class RandomScoreFunctionTests extends ESIntegTestCase {
}
public void testScoreAccessWithinScript() throws Exception {
assertAcked(prepareCreate("test").addMapping("type", "body", "type=string", "index",
assertAcked(prepareCreate("test").addMapping("type", "body", "type=text", "index",
"type=" + randomFrom("short", "float", "long", "integer", "double")));
ensureYellow();

View File

@ -87,9 +87,9 @@ public class SearchFieldsTests extends ESIntegTestCase {
// _timestamp is randomly enabled via templates but we don't want it here to test stored fields behaviour
.startObject("_timestamp").field("enabled", false).endObject()
.startObject("properties")
.startObject("field1").field("type", "string").field("store", true).endObject()
.startObject("field2").field("type", "string").field("store", false).endObject()
.startObject("field3").field("type", "string").field("store", true).endObject()
.startObject("field1").field("type", "text").field("store", true).endObject()
.startObject("field2").field("type", "text").field("store", false).endObject()
.startObject("field3").field("type", "text").field("store", true).endObject()
.endObject().endObject().endObject().string();
client().admin().indices().preparePutMapping().setType("type1").setSource(mapping).execute().actionGet();
@ -487,7 +487,7 @@ public class SearchFieldsTests extends ESIntegTestCase {
.startObject("field1").field("type", "object").startObject("properties")
.startObject("field2").field("type", "object").startObject("properties")
.startObject("field3").field("type", "object").startObject("properties")
.startObject("field4").field("type", "string").field("store", true)
.startObject("field4").field("type", "text").field("store", true)
.endObject().endObject()
.endObject().endObject()
.endObject().endObject()
@ -554,7 +554,8 @@ public class SearchFieldsTests extends ESIntegTestCase {
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().execute().actionGet();
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("_source").field("enabled", false).endObject().startObject("properties")
.startObject("string_field").field("type", "string").endObject()
.startObject("text_field").field("type", "text").endObject()
.startObject("keyword_field").field("type", "keyword").endObject()
.startObject("byte_field").field("type", "byte").endObject()
.startObject("short_field").field("type", "short").endObject()
.startObject("integer_field").field("type", "integer").endObject()
@ -569,7 +570,8 @@ public class SearchFieldsTests extends ESIntegTestCase {
client().admin().indices().preparePutMapping().setType("type1").setSource(mapping).execute().actionGet();
client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject()
.field("string_field", "foo")
.field("text_field", "foo")
.field("keyword_field", "foo")
.field("byte_field", (byte) 1)
.field("short_field", (short) 2)
.field("integer_field", 3)
@ -583,7 +585,8 @@ public class SearchFieldsTests extends ESIntegTestCase {
client().admin().indices().prepareRefresh().execute().actionGet();
SearchRequestBuilder builder = client().prepareSearch().setQuery(matchAllQuery())
.addFieldDataField("string_field")
.addFieldDataField("text_field")
.addFieldDataField("keyword_field")
.addFieldDataField("byte_field")
.addFieldDataField("short_field")
.addFieldDataField("integer_field")
@ -599,7 +602,7 @@ public class SearchFieldsTests extends ESIntegTestCase {
Set<String> fields = new HashSet<>(searchResponse.getHits().getAt(0).fields().keySet());
fields.remove(TimestampFieldMapper.NAME); // randomly enabled via templates
assertThat(fields, equalTo(newHashSet("byte_field", "short_field", "integer_field", "long_field",
"float_field", "double_field", "date_field", "boolean_field", "string_field")));
"float_field", "double_field", "date_field", "boolean_field", "text_field", "keyword_field")));
assertThat(searchResponse.getHits().getAt(0).fields().get("byte_field").value().toString(), equalTo("1"));
assertThat(searchResponse.getHits().getAt(0).fields().get("short_field").value().toString(), equalTo("2"));
@ -609,7 +612,8 @@ public class SearchFieldsTests extends ESIntegTestCase {
assertThat(searchResponse.getHits().getAt(0).fields().get("double_field").value(), equalTo((Object) 6.0d));
assertThat(searchResponse.getHits().getAt(0).fields().get("date_field").value(), equalTo((Object) 1332374400000L));
assertThat(searchResponse.getHits().getAt(0).fields().get("boolean_field").value(), equalTo((Object) 1L));
assertThat(searchResponse.getHits().getAt(0).fields().get("text_field").value(), equalTo("foo"));
assertThat(searchResponse.getHits().getAt(0).fields().get("keyword_field").value(), equalTo("foo"));
}
public void testScriptFields() throws Exception {

View File

@ -138,7 +138,7 @@ public class SimpleSortTests extends ESIntegTestCase {
String mapping = jsonBuilder().startObject().startObject("type1").startObject("properties")
.startObject("lvalue").field("type", "long").endObject()
.startObject("dvalue").field("type", "double").endObject()
.startObject("svalue").field("type", "string").endObject()
.startObject("svalue").field("type", "keyword").endObject()
.startObject("gvalue").field("type", "geo_point").endObject()
.endObject().endObject().endObject().string();
assertAcked(prepareCreate("test").addMapping("type1", mapping));
@ -317,7 +317,7 @@ public class SimpleSortTests extends ESIntegTestCase {
public void test2920() throws IOException {
assertAcked(prepareCreate("test").addMapping(
"test",
jsonBuilder().startObject().startObject("test").startObject("properties").startObject("value").field("type", "string")
jsonBuilder().startObject().startObject("test").startObject("properties").startObject("value").field("type", "keyword")
.endObject().endObject().endObject().endObject()));
ensureGreen();
for (int i = 0; i < 10; i++) {

View File

@ -124,7 +124,7 @@ public class SuggestSearchTests extends ESIntegTestCase {
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("properties")
.startObject("text").field("type", "string").field("analyzer", "keyword").endObject()
.startObject("text").field("type", "text").field("analyzer", "keyword").endObject()
.endObject()
.endObject().endObject();
assertAcked(prepareCreate("test_2").addMapping("type1", mapping));
@ -193,10 +193,10 @@ public class SuggestSearchTests extends ESIntegTestCase {
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("properties")
.startObject("name")
.field("type", "string")
.field("type", "text")
.startObject("fields")
.startObject("shingled")
.field("type", "string")
.field("type", "text")
.field("analyzer", "biword")
.field("search_analyzer", "standard")
.endObject()
@ -264,10 +264,10 @@ public class SuggestSearchTests extends ESIntegTestCase {
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("properties")
.startObject("name")
.field("type", "string")
.field("type", "text")
.startObject("fields")
.startObject("shingled")
.field("type", "string")
.field("type", "text")
.field("analyzer", "biword")
.field("search_analyzer", "standard")
.endObject()
@ -426,7 +426,7 @@ public class SuggestSearchTests extends ESIntegTestCase {
// see #2817
public void testStopwordsOnlyPhraseSuggest() throws IOException {
assertAcked(prepareCreate("test").addMapping("typ1", "body", "type=string,analyzer=stopwd").setSettings(
assertAcked(prepareCreate("test").addMapping("typ1", "body", "type=text,analyzer=stopwd").setSettings(
settingsBuilder()
.put("index.analysis.analyzer.stopwd.tokenizer", "whitespace")
.putArray("index.analysis.analyzer.stopwd.filter", "stop")
@ -458,9 +458,9 @@ public class SuggestSearchTests extends ESIntegTestCase {
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
.startObject("_all").field("store", true).field("termVector", "with_positions_offsets").endObject()
.startObject("properties")
.startObject("body").field("type", "string").field("analyzer", "body").endObject()
.startObject("body_reverse").field("type", "string").field("analyzer", "reverse").endObject()
.startObject("bigram").field("type", "string").field("analyzer", "bigram").endObject()
.startObject("body").field("type", "text").field("analyzer", "body").endObject()
.startObject("body_reverse").field("type", "text").field("analyzer", "reverse").endObject()
.startObject("bigram").field("type", "text").field("analyzer", "bigram").endObject()
.endObject()
.endObject().endObject();
assertAcked(builder.addMapping("type1", mapping));
@ -505,15 +505,15 @@ public class SuggestSearchTests extends ESIntegTestCase {
.endObject()
.startObject("properties")
.startObject("body").
field("type", "string").
field("type", "text").
field("analyzer", "body")
.endObject()
.startObject("body_reverse").
field("type", "string").
field("type", "text").
field("analyzer", "reverse")
.endObject()
.startObject("bigram").
field("type", "string").
field("type", "text").
field("analyzer", "bigram")
.endObject()
.endObject()
@ -640,15 +640,15 @@ public class SuggestSearchTests extends ESIntegTestCase {
.endObject()
.startObject("properties")
.startObject("body")
.field("type", "string")
.field("type", "text")
.field("analyzer", "body")
.endObject()
.startObject("body_reverse")
.field("type", "string")
.field("type", "text")
.field("analyzer", "reverse")
.endObject()
.startObject("bigram")
.field("type", "string")
.field("type", "text")
.field("analyzer", "bigram")
.endObject()
.endObject()
@ -707,9 +707,9 @@ public class SuggestSearchTests extends ESIntegTestCase {
.startObject().startObject("type1")
.startObject("_all").field("store", true).field("termVector", "with_positions_offsets").endObject()
.startObject("properties")
.startObject("body").field("type", "string").field("analyzer", "body").endObject()
.startObject("bigram").field("type", "string").field("analyzer", "bigram").endObject()
.startObject("ngram").field("type", "string").field("analyzer", "ngram").endObject()
.startObject("body").field("type", "text").field("analyzer", "body").endObject()
.startObject("bigram").field("type", "text").field("analyzer", "bigram").endObject()
.startObject("ngram").field("type", "text").field("analyzer", "ngram").endObject()
.endObject()
.endObject().endObject();
assertAcked(builder.addMapping("type1", mapping));
@ -802,7 +802,7 @@ public class SuggestSearchTests extends ESIntegTestCase {
XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type2")
.startObject("properties")
.startObject("name")
.field("type", "string")
.field("type", "text")
.field("analyzer", "suggest")
.endObject()
.endObject()
@ -844,7 +844,7 @@ public class SuggestSearchTests extends ESIntegTestCase {
startObject("type1").
startObject("properties").
startObject("name").
field("type", "string").
field("type", "text").
field("analyzer", "suggest").
endObject().
endObject().
@ -903,7 +903,7 @@ public class SuggestSearchTests extends ESIntegTestCase {
.endObject()
.startObject("properties")
.startObject("body")
.field("type", "string")
.field("type", "text")
.field("analyzer", "body")
.endObject()
.endObject()
@ -961,7 +961,7 @@ public class SuggestSearchTests extends ESIntegTestCase {
.startObject("type1")
.startObject("properties")
.startObject("title")
.field("type", "string")
.field("type", "text")
.field("analyzer", "text")
.endObject()
.endObject()
@ -1106,7 +1106,7 @@ public class SuggestSearchTests extends ESIntegTestCase {
.startObject("type1")
.startObject("properties")
.startObject("title")
.field("type", "string")
.field("type", "text")
.field("analyzer", "text")
.endObject()
.endObject()

View File

@ -22,7 +22,7 @@
type:
properties:
text:
type: string
type: text
analyzer: my_analyzer
- do:
cluster.health:

View File

@ -10,7 +10,7 @@
type:
properties:
text:
type: string
type: text
analyzer: kuromoji
- do:
cluster.health:

View File

@ -22,7 +22,7 @@
type:
properties:
text:
type: string
type: text
analyzer: my_analyzer
- do:
cluster.health:

View File

@ -10,7 +10,7 @@
type:
properties:
text:
type: string
type: text
analyzer: smartcn
- do:
cluster.health:

View File

@ -10,7 +10,7 @@
type:
properties:
text:
type: string
type: text
analyzer: polish
- do:
cluster.health:

View File

@ -295,7 +295,7 @@ public class AttachmentMapper extends FieldMapper {
if (typeNode != null) {
type = typeNode.toString();
} else {
type = "string";
type = "text";
}
Mapper.TypeParser typeParser = parserContext.typeParser(type);
Mapper.Builder<?, ?> mapperBuilder = typeParser.parse(propName, propNode, parserContext);

View File

@ -13,7 +13,7 @@ setup:
"type": "attachment"
"fields":
"content" :
"type": "string"
"type": "text"
"store" : true
"term_vector": "with_positions_offsets"

View File

@ -9,7 +9,7 @@
index: test
body:
mappings:
type1: { "properties": { "foo": { "type": "string", "fields": { "hash": { "type": "murmur3" } } } } }
type1: { "properties": { "foo": { "type": "text", "fields": { "hash": { "type": "murmur3" } } } } }
- do:
index:

View File

@ -56,7 +56,7 @@ public class SizeMappingIT extends ESIntegTestCase {
assertSizeMappingEnabled(index, type, true);
// update some field in the mapping
XContentBuilder updateMappingBuilder = jsonBuilder().startObject().startObject("properties").startObject("otherField").field("type", "string").endObject().endObject();
XContentBuilder updateMappingBuilder = jsonBuilder().startObject().startObject("properties").startObject("otherField").field("type", "text").endObject().endObject();
PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping(index).setType(type).setSource(updateMappingBuilder).get();
assertAcked(putMappingResponse);