Disable fielddata on text fields by defaults. #17386

`text` fields will have fielddata disabled by default. Fielddata can still be
enabled on an existing index by setting `fielddata=true` in the mappings.
This commit is contained in:
Adrien Grand 2016-03-29 11:37:53 +02:00
parent af976a6673
commit 068c788ec8
55 changed files with 219 additions and 97 deletions

View File

@ -43,7 +43,6 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import static org.elasticsearch.index.mapper.core.TypeParsers.parseMultiField;
import static org.elasticsearch.index.mapper.core.TypeParsers.parseTextField;
/** A {@link FieldMapper} for full-text fields. */
@ -60,7 +59,6 @@ public class TextFieldMapper extends FieldMapper implements AllFieldMapper.Inclu
public static final MappedFieldType FIELD_TYPE = new TextFieldType();
static {
FIELD_TYPE.setTokenized(true);
FIELD_TYPE.freeze();
}
@ -177,8 +175,8 @@ public class TextFieldMapper extends FieldMapper implements AllFieldMapper.Inclu
private int fielddataMinSegmentSize;
public TextFieldType() {
// TODO: change the default to false
fielddata = true;
setTokenized(true);
fielddata = false;
fielddataMinFrequency = Defaults.FIELDDATA_MIN_FREQUENCY;
fielddataMaxFrequency = Defaults.FIELDDATA_MAX_FREQUENCY;
fielddataMinSegmentSize = Defaults.FIELDDATA_MIN_SEGMENT_SIZE;

View File

@ -163,7 +163,7 @@ public class IndexAliasesIT extends ESIntegTestCase {
public void testSearchingFilteringAliasesSingleIndex() throws Exception {
logger.info("--> creating index [test]");
assertAcked(prepareCreate("test").addMapping("type1", "id", "type=text", "name", "type=text"));
assertAcked(prepareCreate("test").addMapping("type1", "id", "type=text", "name", "type=text,fielddata=true"));
ensureGreen();

View File

@ -35,6 +35,7 @@ public class FieldDataLoadingIT extends ESIntegTestCase {
.addMapping("type", jsonBuilder().startObject().startObject("type").startObject("properties")
.startObject("name")
.field("type", "text")
.field("fielddata", true)
.field("eager_global_ordinals", true)
.endObject()
.endObject().endObject().endObject()));

View File

@ -64,6 +64,7 @@ public class FilterFieldDataTests extends AbstractFieldDataTestCase {
{
ifdService.clear();
MappedFieldType ft = new TextFieldMapper.Builder("high_freq")
.fielddata(true)
.fielddataFrequencyFilter(0, random.nextBoolean() ? 100 : 0.5d, 0)
.build(builderCtx).fieldType();
IndexOrdinalsFieldData fieldData = ifdService.getForField(ft);
@ -76,6 +77,7 @@ public class FilterFieldDataTests extends AbstractFieldDataTestCase {
{
ifdService.clear();
MappedFieldType ft = new TextFieldMapper.Builder("high_freq")
.fielddata(true)
.fielddataFrequencyFilter(random.nextBoolean() ? 101 : 101d/200.0d, 201, 100)
.build(builderCtx).fieldType();
IndexOrdinalsFieldData fieldData = ifdService.getForField(ft);
@ -88,6 +90,7 @@ public class FilterFieldDataTests extends AbstractFieldDataTestCase {
{
ifdService.clear(); // test # docs with value
MappedFieldType ft = new TextFieldMapper.Builder("med_freq")
.fielddata(true)
.fielddataFrequencyFilter(random.nextBoolean() ? 101 : 101d/200.0d, Integer.MAX_VALUE, 101)
.build(builderCtx).fieldType();
IndexOrdinalsFieldData fieldData = ifdService.getForField(ft);
@ -101,6 +104,7 @@ public class FilterFieldDataTests extends AbstractFieldDataTestCase {
{
ifdService.clear();
MappedFieldType ft = new TextFieldMapper.Builder("med_freq")
.fielddata(true)
.fielddataFrequencyFilter(random.nextBoolean() ? 101 : 101d/200.0d, Integer.MAX_VALUE, 101)
.build(builderCtx).fieldType();
IndexOrdinalsFieldData fieldData = ifdService.getForField(ft);

View File

@ -102,7 +102,8 @@ public class CopyToMapperIntegrationIT extends ESIntegTestCase {
.startObject().startObject("template_all")
.field("match", "*")
.field("match_mapping_type", "string")
.startObject("mapping").field("type", "text").field("copy_to", "{name}_raw").endObject()
.startObject("mapping").field("type", "text").field("fielddata", true)
.field("copy_to", "{name}_raw").endObject()
.endObject().endObject()
.endArray();

View File

@ -405,22 +405,33 @@ public class TextFieldMapperTests extends ESSingleNodeTestCase {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("field")
.field("type", "text")
.field("fielddata", false)
.endObject().endObject()
.endObject().endObject().string();
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
assertEquals(mapping, mapper.mappingSource().toString());
DocumentMapper disabledMapper = parser.parse("type", new CompressedXContent(mapping));
assertEquals(mapping, disabledMapper.mappingSource().toString());
IllegalStateException e = expectThrows(IllegalStateException.class,
() -> mapper.mappers().getMapper("field").fieldType().fielddataBuilder());
() -> disabledMapper.mappers().getMapper("field").fieldType().fielddataBuilder());
assertThat(e.getMessage(), containsString("Fielddata is disabled"));
mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("field")
.field("type", "text")
.field("fielddata", true)
.endObject().endObject()
.endObject().endObject().string();
DocumentMapper enabledMapper = parser.parse("type", new CompressedXContent(mapping));
assertEquals(mapping, enabledMapper.mappingSource().toString());
enabledMapper.mappers().getMapper("field").fieldType().fielddataBuilder(); // no exception this time
}
public void testFrequencyFilter() throws IOException {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("field")
.field("type", "text")
.field("fielddata", true)
.startObject("fielddata_frequency_filter")
.field("min", 2d)
.field("min_segment_size", 1000)

View File

@ -103,7 +103,8 @@ public class CircuitBreakerServiceIT extends ESIntegTestCase {
logger.info("--> noop breakers used, skipping test");
return;
}
assertAcked(prepareCreate("cb-test", 1, settingsBuilder().put(SETTING_NUMBER_OF_REPLICAS, between(0, 1))));
assertAcked(prepareCreate("cb-test", 1, settingsBuilder().put(SETTING_NUMBER_OF_REPLICAS, between(0, 1)))
.addMapping("type", "test", "type=text,fielddata=true"));
final Client client = client();
// index some different terms so we have some field data for loading
@ -148,7 +149,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\": \"text\",\"fielddata_frequency_filter\": {\"max\": 10000}}}}}}"));
"{\"type\": \"text\",\"fielddata\": true,\"fielddata_frequency_filter\": {\"max\": 10000}}}}}}"));
ensureGreen("ramtest");
@ -197,7 +198,8 @@ public class CircuitBreakerServiceIT extends ESIntegTestCase {
logger.info("--> noop breakers used, skipping test");
return;
}
assertAcked(prepareCreate("cb-test", 1, settingsBuilder().put(SETTING_NUMBER_OF_REPLICAS, between(0, 1))));
assertAcked(prepareCreate("cb-test", 1, settingsBuilder().put(SETTING_NUMBER_OF_REPLICAS, between(0, 1)))
.addMapping("type", "test", "type=text,fielddata=true"));
Client client = client();
// index some different terms so we have some field data for loading

View File

@ -58,10 +58,7 @@ import java.io.IOException;
import java.util.EnumSet;
import java.util.Random;
import static org.elasticsearch.cluster.metadata.IndexMetaData.PROTO;
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.common.xcontent.XContentFactory.contentBuilder;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAllSuccessful;
@ -97,7 +94,10 @@ public class IndexStatsIT extends ESIntegTestCase {
}
public void testFieldDataStats() {
client().admin().indices().prepareCreate("test").setSettings(settingsBuilder().put("index.number_of_shards", 2)).execute().actionGet();
assertAcked(client().admin().indices().prepareCreate("test")
.setSettings(settingsBuilder().put("index.number_of_shards", 2))
.addMapping("type", "field", "type=text,fielddata=true",
"field2", "type=text,fielddata=true").get());
ensureGreen();
client().prepareIndex("test", "type", "1").setSource("field", "value1", "field2", "value1").execute().actionGet();
client().prepareIndex("test", "type", "2").setSource("field", "value2", "field2", "value2").execute().actionGet();
@ -141,9 +141,9 @@ public class IndexStatsIT extends ESIntegTestCase {
}
public void testClearAllCaches() throws Exception {
client().admin().indices().prepareCreate("test")
assertAcked(client().admin().indices().prepareCreate("test")
.setSettings(settingsBuilder().put("index.number_of_replicas", 0).put("index.number_of_shards", 2))
.execute().actionGet();
.addMapping("type", "field", "type=text,fielddata=true").get());
ensureGreen();
client().admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();
client().prepareIndex("test", "type", "1").setSource("field", "value1").execute().actionGet();
@ -719,7 +719,9 @@ public class IndexStatsIT extends ESIntegTestCase {
}
public void testFieldDataFieldsParam() throws Exception {
createIndex("test1");
assertAcked(client().admin().indices().prepareCreate("test1")
.addMapping("type", "bar", "type=text,fielddata=true",
"baz", "type=text,fielddata=true").get());
ensureGreen();

View File

@ -54,7 +54,7 @@ public class PercolatorAggregationsIT extends ESIntegTestCase {
// Just test the integration with facets and aggregations, not the facet and aggregation functionality!
public void testAggregations() throws Exception {
assertAcked(prepareCreate("test").addMapping("type", "field1", "type=text", "field2", "type=text"));
assertAcked(prepareCreate("test").addMapping("type", "field1", "type=text", "field2", "type=keyword"));
ensureGreen();
int numQueries = scaledRandomIntBetween(250, 500);
@ -119,7 +119,7 @@ public class PercolatorAggregationsIT extends ESIntegTestCase {
// Just test the integration with facets and aggregations, not the facet and aggregation functionality!
public void testAggregationsAndPipelineAggregations() throws Exception {
assertAcked(prepareCreate("test").addMapping("type", "field1", "type=text", "field2", "type=text"));
assertAcked(prepareCreate("test").addMapping("type", "field1", "type=text", "field2", "type=keyword"));
ensureGreen();
int numQueries = scaledRandomIntBetween(250, 500);
@ -204,7 +204,7 @@ public class PercolatorAggregationsIT extends ESIntegTestCase {
public void testSingleShardAggregations() throws Exception {
assertAcked(prepareCreate("test").setSettings(Settings.builder().put(indexSettings()).put("index.number_of_shards", 1))
.addMapping("type", "field1", "type=text", "field2", "type=text"));
.addMapping("type", "field1", "type=text", "field2", "type=keyword"));
ensureGreen();
int numQueries = scaledRandomIntBetween(250, 500);

View File

@ -40,7 +40,7 @@ public class AggregationsIntegrationIT extends ESIntegTestCase {
@Override
public void setupSuiteScopeCluster() throws Exception {
assertAcked(prepareCreate("index").addMapping("type", "f", "type=text").get());
assertAcked(prepareCreate("index").addMapping("type", "f", "type=keyword").get());
ensureYellow("index");
numDocs = randomIntBetween(1, 20);
List<IndexRequestBuilder> docs = new ArrayList<>();

View File

@ -117,7 +117,7 @@ public class CombiIT extends ESIntegTestCase {
prepareCreate("idx").addMapping("type", jsonBuilder()
.startObject()
.startObject("type").startObject("properties")
.startObject("name").field("type", "text").endObject()
.startObject("name").field("type", "keyword").endObject()
.startObject("value").field("type", "integer").endObject()
.endObject().endObject()
.endObject()).execute().actionGet();

View File

@ -34,13 +34,15 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.search.aggregations.AggregationBuilders.sum;
import static org.elasticsearch.search.aggregations.AggregationBuilders.terms;
import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilders.maxBucket;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse;
public class MetaDataIT extends ESIntegTestCase {
public void testMetaDataSetOnAggregationResult() throws Exception {
createIndex("idx");
assertAcked(client().admin().indices().prepareCreate("idx")
.addMapping("type", "name", "type=keyword").get());
IndexRequestBuilder[] builders = new IndexRequestBuilder[randomInt(30)];
for (int i = 0; i < builders.length; i++) {
String name = "name_" + randomIntBetween(1, 10);

View File

@ -54,7 +54,7 @@ public class MissingValueIT extends ESIntegTestCase {
@Override
protected void setupSuiteScopeCluster() throws Exception {
assertAcked(prepareCreate("idx").addMapping("type", "date", "type=date", "location", "type=geo_point").get());
assertAcked(prepareCreate("idx").addMapping("type", "date", "type=date", "location", "type=geo_point", "str", "type=keyword").get());
indexRandom(true,
client().prepareIndex("idx", "type", "1").setSource(),
client().prepareIndex("idx", "type", "2").setSource("str", "foo", "long", 3L, "double", 5.5, "date", "2015-05-07", "location", "1,2"));

View File

@ -66,8 +66,8 @@ public class ChildrenIT extends ESIntegTestCase {
public void setupSuiteScopeCluster() throws Exception {
assertAcked(
prepareCreate("test")
.addMapping("article")
.addMapping("comment", "_parent", "type=article")
.addMapping("article", "category", "type=keyword")
.addMapping("comment", "_parent", "type=article", "commenter", "type=keyword")
);
List<IndexRequestBuilder> requests = new ArrayList<>();
@ -295,8 +295,8 @@ children("non-existing", "xyz")
String childType = "variantsku";
assertAcked(
prepareCreate(indexName)
.addMapping(masterType, "brand", "type=text", "name", "type=text", "material", "type=text")
.addMapping(childType, "_parent", "type=masterprod", "color", "type=text", "size", "type=text")
.addMapping(masterType, "brand", "type=text", "name", "type=keyword", "material", "type=text")
.addMapping(childType, "_parent", "type=masterprod", "color", "type=keyword", "size", "type=keyword")
);
List<IndexRequestBuilder> requests = new ArrayList<>();
@ -358,7 +358,7 @@ children("non-existing", "xyz")
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
)
.addMapping(grandParentType)
.addMapping(grandParentType, "name", "type=keyword")
.addMapping(parentType, "_parent", "type=" + grandParentType)
.addMapping(childType, "_parent", "type=" + parentType)
);

View File

@ -34,6 +34,7 @@ import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.elasticsearch.search.aggregations.AggregationBuilders.avg;
import static org.elasticsearch.search.aggregations.AggregationBuilders.histogram;
import static org.elasticsearch.search.aggregations.AggregationBuilders.missing;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
@ -49,7 +50,8 @@ public class MissingIT extends ESIntegTestCase {
@Override
public void setupSuiteScopeCluster() throws Exception {
createIndex("idx");
assertAcked(client().admin().indices().prepareCreate("idx")
.addMapping("type", "tag", "type=keyword").get());
List<IndexRequestBuilder> builders = new ArrayList<>();
numDocs = randomIntBetween(5, 20);
numDocsMissing = randomIntBetween(1, numDocs - 1);

View File

@ -39,6 +39,7 @@ import static org.elasticsearch.search.aggregations.AggregationBuilders.avg;
import static org.elasticsearch.search.aggregations.AggregationBuilders.extendedStats;
import static org.elasticsearch.search.aggregations.AggregationBuilders.histogram;
import static org.elasticsearch.search.aggregations.AggregationBuilders.terms;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse;
import static org.hamcrest.core.IsNull.notNullValue;
@ -108,7 +109,8 @@ public class NaNSortingIT extends ESIntegTestCase {
@Override
public void setupSuiteScopeCluster() throws Exception {
createIndex("idx");
assertAcked(client().admin().indices().prepareCreate("idx")
.addMapping("type", "string_value", "type=keyword").get());
final int numDocs = randomIntBetween(2, 10);
for (int i = 0; i < numDocs; ++i) {
final long value = randomInt(5);

View File

@ -297,7 +297,7 @@ public class NestedIT extends ESIntegTestCase {
public void testNestNestedAggs() throws Exception {
SearchResponse response = client().prepareSearch("idx_nested_nested_aggs")
.addAggregation(nested("level1", "nested1")
.subAggregation(terms("a").field("nested1.a")
.subAggregation(terms("a").field("nested1.a.keyword")
.collectMode(aggCollectionMode)
.subAggregation(nested("level2", "nested1.nested2")
.subAggregation(sum("sum").field("nested1.nested2.b")))))
@ -463,7 +463,7 @@ public class NestedIT extends ESIntegTestCase {
assertAcked(
prepareCreate("idx4")
.setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 0))
.addMapping("product", "categories", "type=text", "name", "type=text", "property", "type=nested")
.addMapping("product", "categories", "type=keyword", "name", "type=text", "property", "type=nested")
);
ensureGreen("idx4");

View File

@ -66,9 +66,9 @@ public class ReverseNestedIT extends ESIntegTestCase {
.addMapping(
"type1",
jsonBuilder().startObject().startObject("properties")
.startObject("field1").field("type", "text").endObject()
.startObject("field1").field("type", "keyword").endObject()
.startObject("nested1").field("type", "nested").startObject("properties")
.startObject("field2").field("type", "text").endObject()
.startObject("field2").field("type", "keyword").endObject()
.endObject().endObject()
.endObject().endObject()
)
@ -76,9 +76,9 @@ public class ReverseNestedIT extends ESIntegTestCase {
"type2",
jsonBuilder().startObject().startObject("properties")
.startObject("nested1").field("type", "nested").startObject("properties")
.startObject("field1").field("type", "text").endObject()
.startObject("field1").field("type", "keyword").endObject()
.startObject("nested2").field("type", "nested").startObject("properties")
.startObject("field2").field("type", "text").endObject()
.startObject("field2").field("type", "keyword").endObject()
.endObject().endObject()
.endObject().endObject()
.endObject().endObject()
@ -487,17 +487,17 @@ public class ReverseNestedIT extends ESIntegTestCase {
.startObject("category")
.field("type", "nested")
.startObject("properties")
.startObject("name").field("type", "text").endObject()
.startObject("name").field("type", "keyword").endObject()
.endObject()
.endObject()
.startObject("sku")
.field("type", "nested")
.startObject("properties")
.startObject("sku_type").field("type", "text").endObject()
.startObject("sku_type").field("type", "keyword").endObject()
.startObject("colors")
.field("type", "nested")
.startObject("properties")
.startObject("name").field("type", "text").endObject()
.startObject("name").field("type", "keyword").endObject()
.endObject()
.endObject()
.endObject()

View File

@ -78,7 +78,8 @@ public class ShardReduceIT extends ESIntegTestCase {
@Override
public void setupSuiteScopeCluster() throws Exception {
assertAcked(prepareCreate("idx")
.addMapping("type", "nested", "type=nested", "ip", "type=ip", "location", "type=geo_point"));
.addMapping("type", "nested", "type=nested", "ip", "type=ip",
"location", "type=geo_point", "term-s", "type=keyword"));
indexRandom(true,
indexDoc("2014-01-01", 1),

View File

@ -77,7 +77,7 @@ public class SignificantTermsIT extends ESIntegTestCase {
public void setupSuiteScopeCluster() throws Exception {
assertAcked(prepareCreate("test").setSettings(SETTING_NUMBER_OF_SHARDS, 5, SETTING_NUMBER_OF_REPLICAS, 0).addMapping("fact",
"_routing", "required=true", "routing_id", "type=keyword", "fact_category",
"type=integer,index=true", "description", "type=text,index=true"));
"type=integer,index=true", "description", "type=text,fielddata=true"));
createIndex("idx_unmapped");
ensureGreen();

View File

@ -291,8 +291,8 @@ public class SignificantTermsSignificanceScoreIT extends ESIntegTestCase {
public void testDeletesIssue7951() throws Exception {
String settings = "{\"index.number_of_shards\": 1, \"index.number_of_replicas\": 0}";
String mappings = "{\"doc\": {\"properties\":{\"text\": {\"type\":\"keyword\"}}}}";
assertAcked(prepareCreate(INDEX_NAME).setSettings(settings).addMapping("doc", mappings));
assertAcked(prepareCreate(INDEX_NAME).setSettings(settings)
.addMapping("doc", "text", "type=keyword", CLASS_FIELD, "type=keyword"));
String[] cat1v1 = {"constant", "one"};
String[] cat1v2 = {"constant", "uno"};
String[] cat2v1 = {"constant", "two"};
@ -427,7 +427,7 @@ public class SignificantTermsSignificanceScoreIT extends ESIntegTestCase {
private void indexEqualTestData() throws ExecutionException, InterruptedException {
assertAcked(prepareCreate("test").setSettings(SETTING_NUMBER_OF_SHARDS, 1, SETTING_NUMBER_OF_REPLICAS, 0).addMapping("doc",
"text", "type=text", "class", "type=text"));
"text", "type=text,fielddata=true", "class", "type=keyword"));
createIndex("idx_unmapped");
ensureGreen();
@ -496,8 +496,11 @@ public class SignificantTermsSignificanceScoreIT extends ESIntegTestCase {
}
private void indexRandomFrequencies01(String type) throws ExecutionException, InterruptedException {
String mappings = "{\"" + DOC_TYPE + "\": {\"properties\":{\"" + TEXT_FIELD + "\": {\"type\":\"" + type + "\"}}}}";
assertAcked(prepareCreate(INDEX_NAME).addMapping(DOC_TYPE, mappings));
String textMappings = "type=" + type;
if (type.equals("text")) {
textMappings += ",fielddata=true";
}
assertAcked(prepareCreate(INDEX_NAME).addMapping(DOC_TYPE, TEXT_FIELD, textMappings, CLASS_FIELD, "type=keyword"));
String[] gb = {"0", "1"};
List<IndexRequestBuilder> indexRequestBuilderList = new ArrayList<>();
for (int i = 0; i < randomInt(20); i++) {

View File

@ -60,7 +60,8 @@ public class TermsDocCountErrorIT extends ESIntegTestCase {
@Override
public void setupSuiteScopeCluster() throws Exception {
createIndex("idx");
assertAcked(client().admin().indices().prepareCreate("idx")
.addMapping("type", STRING_FIELD_NAME, "type=keyword").get());
List<IndexRequestBuilder> builders = new ArrayList<>();
int numDocs = between(10, 200);
int numUniqueTerms = between(2,numDocs/2);
@ -72,7 +73,9 @@ public class TermsDocCountErrorIT extends ESIntegTestCase {
.field(DOUBLE_FIELD_NAME, 1.0 * randomInt(numUniqueTerms))
.endObject()));
}
assertAcked(prepareCreate("idx_single_shard").setSettings(Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)));
assertAcked(prepareCreate("idx_single_shard")
.addMapping("type", STRING_FIELD_NAME, "type=keyword")
.setSettings(Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)));
for (int i = 0; i < numDocs; i++) {
builders.add(client().prepareIndex("idx_single_shard", "type", ""+i).setSource(jsonBuilder()
.startObject()

View File

@ -51,11 +51,14 @@ public class TermsShardMinDocCountIT extends ESIntegTestCase {
// see https://github.com/elastic/elasticsearch/issues/5998
public void testShardMinDocCountSignificantTermsTest() throws Exception {
String termtype = "text";
String textMappings;
if (randomBoolean()) {
termtype = "long";
textMappings = "type=long";
} else {
textMappings = "type=text,fielddata=true";
}
assertAcked(prepareCreate(index).setSettings(SETTING_NUMBER_OF_SHARDS, 1, SETTING_NUMBER_OF_REPLICAS, 0).addMapping(type, "{\"properties\":{\"text\": {\"type\": \"" + termtype + "\"}}}"));
assertAcked(prepareCreate(index).setSettings(SETTING_NUMBER_OF_SHARDS, 1, SETTING_NUMBER_OF_REPLICAS, 0)
.addMapping(type, "text", textMappings));
ensureYellow(index);
List<IndexRequestBuilder> indexBuilders = new ArrayList<>();
@ -111,8 +114,11 @@ public class TermsShardMinDocCountIT extends ESIntegTestCase {
public void testShardMinDocCountTermsTest() throws Exception {
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 + "\"}}}"));
String termMappings = "type=" + termtype;
if (termtype.equals("text")) {
termMappings += ",fielddata=true";
}
assertAcked(prepareCreate(index).setSettings(SETTING_NUMBER_OF_SHARDS, 1, SETTING_NUMBER_OF_REPLICAS, 0).addMapping(type, "text", termMappings));
ensureYellow(index);
List<IndexRequestBuilder> indexBuilders = new ArrayList<>();

View File

@ -101,12 +101,18 @@ public class TopHitsIT extends ESIntegTestCase {
@Override
public void setupSuiteScopeCluster() throws Exception {
createIndex("idx");
assertAcked(prepareCreate("idx").addMapping("type", TERMS_AGGS_FIELD, "type=keyword", "group", "type=keyword"));
createIndex("empty");
assertAcked(prepareCreate("articles").addMapping("article", jsonBuilder().startObject().startObject("article").startObject("properties")
.startObject(TERMS_AGGS_FIELD)
.field("type", "keyword")
.endObject()
.startObject("comments")
.field("type", "nested")
.startObject("properties")
.startObject("user")
.field("type", "keyword")
.endObject()
.startObject("date")
.field("type", "long")
.endObject()

View File

@ -59,7 +59,8 @@ public class AvgBucketIT extends ESIntegTestCase {
@Override
public void setupSuiteScopeCluster() throws Exception {
createIndex("idx");
assertAcked(client().admin().indices().prepareCreate("idx")
.addMapping("type", "tag", "type=keyword").get());
createIndex("idx_unmapped");
numDocs = randomIntBetween(6, 20);

View File

@ -62,7 +62,8 @@ public class ExtendedStatsBucketIT extends ESIntegTestCase {
@Override
public void setupSuiteScopeCluster() throws Exception {
createIndex("idx");
assertAcked(client().admin().indices().prepareCreate("idx")
.addMapping("type", "tag", "type=keyword").get());
createIndex("idx_unmapped");
numDocs = randomIntBetween(6, 20);

View File

@ -63,7 +63,8 @@ public class MaxBucketIT extends ESIntegTestCase {
@Override
public void setupSuiteScopeCluster() throws Exception {
createIndex("idx");
assertAcked(client().admin().indices().prepareCreate("idx")
.addMapping("type", "tag", "type=keyword").get());
createIndex("idx_unmapped");
numDocs = randomIntBetween(6, 20);

View File

@ -60,7 +60,8 @@ public class MinBucketIT extends ESIntegTestCase {
@Override
public void setupSuiteScopeCluster() throws Exception {
createIndex("idx");
assertAcked(client().admin().indices().prepareCreate("idx")
.addMapping("type", "tag", "type=keyword").get());
createIndex("idx_unmapped");
numDocs = randomIntBetween(6, 20);

View File

@ -64,7 +64,8 @@ public class PercentilesBucketIT extends ESIntegTestCase {
@Override
public void setupSuiteScopeCluster() throws Exception {
createIndex("idx");
assertAcked(client().admin().indices().prepareCreate("idx")
.addMapping("type", "tag", "type=keyword").get());
createIndex("idx_unmapped");
numDocs = randomIntBetween(6, 20);

View File

@ -60,7 +60,8 @@ public class StatsBucketIT extends ESIntegTestCase {
@Override
public void setupSuiteScopeCluster() throws Exception {
createIndex("idx");
assertAcked(client().admin().indices().prepareCreate("idx")
.addMapping("type", "tag", "type=keyword").get());
createIndex("idx_unmapped");
numDocs = randomIntBetween(6, 20);

View File

@ -59,7 +59,8 @@ public class SumBucketIT extends ESIntegTestCase {
@Override
public void setupSuiteScopeCluster() throws Exception {
createIndex("idx");
assertAcked(client().admin().indices().prepareCreate("idx")
.addMapping("type", "tag", "type=keyword").get());
createIndex("idx_unmapped");
numDocs = randomIntBetween(6, 20);

View File

@ -413,7 +413,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
public void testScopedFacet() throws Exception {
assertAcked(prepareCreate("test")
.addMapping("parent")
.addMapping("child", "_parent", "type=parent"));
.addMapping("child", "_parent", "type=parent", "c_field", "type=keyword"));
ensureGreen();
// index simple data
@ -825,8 +825,8 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
public void testSimpleQueryRewrite() throws Exception {
assertAcked(prepareCreate("test")
.addMapping("parent", "p_field", "type=text")
.addMapping("child", "_parent", "type=parent", "c_field", "type=text"));
.addMapping("parent", "p_field", "type=keyword")
.addMapping("child", "_parent", "type=parent", "c_field", "type=keyword"));
ensureGreen();
// index simple data

View File

@ -81,6 +81,7 @@ public class InnerHitsIT extends ESIntegTestCase {
.startObject("properties")
.startObject("message")
.field("type", "text")
.field("fielddata", true)
.endObject()
.endObject()
.endObject()
@ -282,7 +283,7 @@ public class InnerHitsIT extends ESIntegTestCase {
public void testSimpleParentChild() throws Exception {
assertAcked(prepareCreate("articles")
.addMapping("article", "title", "type=text")
.addMapping("comment", "_parent", "type=article", "message", "type=text")
.addMapping("comment", "_parent", "type=article", "message", "type=text,fielddata=true")
);
List<IndexRequestBuilder> requests = new ArrayList<>();
@ -903,9 +904,14 @@ public class InnerHitsIT extends ESIntegTestCase {
.startObject("properties")
.startObject("nested1")
.field("type", "nested")
.startObject("properties")
.startObject("n_field1")
.field("type", "keyword")
.endObject()
.endObject()
.endObject()
.startObject("field1")
.field("type", "long")
.field("type", "long")
.endObject()
.endObject()
.endObject()

View File

@ -872,8 +872,8 @@ public class SimpleNestedIT extends ESIntegTestCase {
.startObject("users")
.field("type", "nested")
.startObject("properties")
.startObject("first").field("type", "text").endObject()
.startObject("last").field("type", "text").endObject()
.startObject("first").field("type", "keyword").endObject()
.startObject("last").field("type", "keyword").endObject()
.startObject("workstations")
.field("type", "nested")
.startObject("properties")

View File

@ -792,7 +792,7 @@ public class SearchQueryIT extends ESIntegTestCase {
MultiMatchQueryBuilder builder = multiMatchQuery("value1 value2 value4", "field1", "field2");
SearchResponse searchResponse = client().prepareSearch().setQuery(builder)
.addAggregation(AggregationBuilders.terms("field1").field("field1")).get();
.addAggregation(AggregationBuilders.terms("field1").field("field1.keyword")).get();
assertHitCount(searchResponse, 2L);
// this uses dismax so scores are equal and the order can be arbitrary

View File

@ -138,7 +138,7 @@ public class DuelScrollIT extends ESIntegTestCase {
.field("type", "long")
.endObject()
.startObject("field2")
.field("type", "text")
.field("type", "keyword")
.endObject()
.startObject("nested")
.field("type", "nested")
@ -147,7 +147,7 @@ public class DuelScrollIT extends ESIntegTestCase {
.field("type", "long")
.endObject()
.startObject("field4")
.field("type", "text")
.field("type", "keyword")
.endObject()
.endObject()
.endObject()

View File

@ -465,7 +465,7 @@ public class SearchScrollIT extends ESIntegTestCase {
public void testStringSortMissingAscTerminates() throws Exception {
assertAcked(prepareCreate("test")
.setSettings(Settings.settingsBuilder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0))
.addMapping("test", "no_field", "type=text", "some_field", "type=text"));
.addMapping("test", "no_field", "type=keyword", "some_field", "type=keyword"));
client().prepareIndex("test", "test", "1").setSource("some_field", "test").get();
refresh();

View File

@ -41,6 +41,7 @@ import java.util.Collections;
import java.util.Arrays;
import java.util.concurrent.ExecutionException;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.hamcrest.Matchers.equalTo;
@ -51,7 +52,8 @@ public class SearchAfterIT extends ESIntegTestCase {
private static final int NUM_DOCS = 100;
public void testsShouldFail() throws Exception {
createIndex("test");
assertAcked(client().admin().indices().prepareCreate("test")
.addMapping("type1", "field2", "type=keyword").get());
ensureGreen();
indexRandom(true, client().prepareIndex("test", "type1", "0").setSource("field1", 0, "field2", "toto"));
try {
@ -139,7 +141,8 @@ public class SearchAfterIT extends ESIntegTestCase {
}
public void testWithNullStrings() throws ExecutionException, InterruptedException {
createIndex("test");
assertAcked(client().admin().indices().prepareCreate("test")
.addMapping("type1", "field2", "type=keyword").get());
ensureGreen();
indexRandom(true,
client().prepareIndex("test", "type1", "0").setSource("field1", 0),

View File

@ -180,7 +180,8 @@ public class FieldSortIT extends ESIntegTestCase {
}
public void testTrackScores() throws Exception {
createIndex("test");
assertAcked(client().admin().indices().prepareCreate("test")
.addMapping("type", "svalue", "type=keyword").get());
ensureGreen();
index("test", "type1", jsonBuilder().startObject()
.field("id", "1")
@ -294,7 +295,8 @@ public class FieldSortIT extends ESIntegTestCase {
}
public void test3078() {
createIndex("test");
assertAcked(client().admin().indices().prepareCreate("test")
.addMapping("type", "field", "type=keyword").get());
ensureGreen();
for (int i = 1; i < 101; i++) {
@ -423,7 +425,8 @@ public class FieldSortIT extends ESIntegTestCase {
}
public void testIssue2986() {
createIndex("test");
assertAcked(client().admin().indices().prepareCreate("test")
.addMapping("type", "field1", "type=keyword").get());
client().prepareIndex("test", "post", "1").setSource("{\"field1\":\"value1\"}").execute().actionGet();
client().prepareIndex("test", "post", "2").setSource("{\"field1\":\"value2\"}").execute().actionGet();
@ -444,7 +447,8 @@ public class FieldSortIT extends ESIntegTestCase {
} catch (Exception e) {
// ignore
}
createIndex("test");
assertAcked(client().admin().indices().prepareCreate("test")
.addMapping("type", "tag", "type=keyword").get());
ensureGreen();
client().prepareIndex("test", "type", "1").setSource("tag", "alpha").execute().actionGet();
refresh();
@ -1414,6 +1418,7 @@ public class FieldSortIT extends ESIntegTestCase {
.startObject("properties")
.startObject("foo")
.field("type", "text")
.field("fielddata", true)
.startObject("fields")
.startObject("sub")
.field("type", "keyword")

View File

@ -333,7 +333,7 @@ public class GeoDistanceSortBuilderIT extends ESIntegTestCase {
public void testCrossIndexIgnoreUnmapped() throws Exception {
assertAcked(prepareCreate("test1").addMapping(
"type", "str_field1", "type=keyword",
"type", "str_field", "type=keyword",
"long_field", "type=long",
"double_field", "type=double").get());
assertAcked(prepareCreate("test2").get());

View File

@ -308,7 +308,7 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase {
int numRequestedPayloadFields = randomIntBetween(2, numPayloadFields);
List<String> payloadFields = new ArrayList<>(numRequestedPayloadFields);
for (int i = 0; i < numRequestedPayloadFields; i++) {
payloadFields.add("test_field" + i);
payloadFields.add("test_field" + i + ".keyword");
}
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg")
@ -324,7 +324,7 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase {
assertThat(option.getText().toString(), equalTo("suggestion" + id));
assertThat(option.getPayload().size(), equalTo(numRequestedPayloadFields));
for (int i = 0; i < numRequestedPayloadFields; i++) {
List<Object> fieldValue = option.getPayload().get("test_field" + i);
List<Object> fieldValue = option.getPayload().get("test_field" + i + ".keyword");
assertNotNull(fieldValue);
assertThat(fieldValue.size(), equalTo(1));
assertThat((String)fieldValue.get(0), equalTo(i + "value" + id));
@ -961,6 +961,12 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase {
private void createIndexAndMappingAndSettings(Settings settings, CompletionMappingBuilder completionMappingBuilder) throws IOException {
XContentBuilder mapping = jsonBuilder().startObject()
.startObject(TYPE).startObject("properties")
.startObject("test_field")
.field("type", "keyword")
.endObject()
.startObject("title")
.field("type", "keyword")
.endObject()
.startObject(FIELD)
.field("type", "completion")
.field("analyzer", completionMappingBuilder.indexAnalyzer)

View File

@ -76,8 +76,12 @@ public class SharedSignificantTermsTestMethods {
}
public static void index01Docs(String type, String settings, ESIntegTestCase testCase) throws ExecutionException, InterruptedException {
String mappings = "{\"doc\": {\"properties\":{\"text\": {\"type\":\"" + type + "\"}}}}";
assertAcked(testCase.prepareCreate(INDEX_NAME).setSettings(settings).addMapping("doc", mappings));
String textMappings = "type=" + type;
if (type.equals("text")) {
textMappings += ",fielddata=true";
}
assertAcked(testCase.prepareCreate(INDEX_NAME).setSettings(settings)
.addMapping("doc", "text", textMappings, CLASS_FIELD, "type=keyword"));
String[] gb = {"0", "1"};
List<IndexRequestBuilder> indexRequestBuilderList = new ArrayList<>();
indexRequestBuilderList.add(client().prepareIndex(INDEX_NAME, DOC_TYPE, "1")

View File

@ -56,6 +56,7 @@ import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
import static org.elasticsearch.search.aggregations.AggregationBuilders.histogram;
import static org.elasticsearch.search.aggregations.AggregationBuilders.sum;
import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilders.bucketScript;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
@ -408,7 +409,8 @@ public class MoreExpressionTests extends ESIntegTestCase {
public void testStringSpecialValueVariable() throws Exception {
// i.e. expression script for term aggregations, which is not allowed
createIndex("test");
assertAcked(client().admin().indices().prepareCreate("test")
.addMapping("doc", "text", "type=keyword").get());
ensureGreen("test");
indexRandom(true,
client().prepareIndex("test", "doc", "1").setSource("text", "hello"),

View File

@ -56,6 +56,7 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.search.aggregations.AggregationBuilders.dateHistogram;
import static org.elasticsearch.search.aggregations.AggregationBuilders.histogram;
import static org.elasticsearch.search.aggregations.AggregationBuilders.terms;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAllSuccessful;
@ -73,7 +74,8 @@ public class MinDocCountTests extends AbstractTermsTestCase {
@Override
public void setupSuiteScopeCluster() throws Exception {
createIndex("idx");
assertAcked(client().admin().indices().prepareCreate("idx")
.addMapping("type", "s", "type=keyword").get());
cardinality = randomIntBetween(8, 30);
final List<IndexRequestBuilder> indexRequests = new ArrayList<>();

View File

@ -539,7 +539,8 @@ public class SearchFieldsTests extends ESIntegTestCase {
// see #8203
public void testSingleValueFieldDatatField() throws ExecutionException, InterruptedException {
createIndex("test");
assertAcked(client().admin().indices().prepareCreate("test")
.addMapping("type", "test_field", "type=keyword").get());
indexRandom(true, client().prepareIndex("test", "type", "1").setSource("test_field", "foobar"));
refresh();
SearchResponse searchResponse = client().prepareSearch("test").setTypes("type").setSource(
@ -554,7 +555,7 @@ 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("text_field").field("type", "text").endObject()
.startObject("text_field").field("type", "text").field("fielddata", true).endObject()
.startObject("keyword_field").field("type", "keyword").endObject()
.startObject("byte_field").field("type", "byte").endObject()
.startObject("short_field").field("type", "short").endObject()

View File

@ -227,6 +227,7 @@ public class SimpleSortTests extends ESIntegTestCase {
// We have to specify mapping explicitly because by the time search is performed dynamic mapping might not
// be propagated to all nodes yet and sort operation fail when the sort field is not defined
String mapping = jsonBuilder().startObject().startObject("type1").startObject("properties")
.startObject("id").field("type", "keyword").endObject()
.startObject("svalue").field("type", "keyword").endObject()
.endObject().endObject().endObject().string();
assertAcked(prepareCreate("test").addMapping("type1", mapping));

View File

@ -68,6 +68,7 @@ import static org.elasticsearch.search.aggregations.AggregationBuilders.histogra
import static org.elasticsearch.search.aggregations.AggregationBuilders.stats;
import static org.elasticsearch.search.aggregations.AggregationBuilders.sum;
import static org.elasticsearch.search.aggregations.AggregationBuilders.terms;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
@ -90,7 +91,10 @@ public class StringTermsTests extends AbstractTermsTestCase {
@Override
public void setupSuiteScopeCluster() throws Exception {
createIndex("idx");
assertAcked(client().admin().indices().prepareCreate("idx")
.addMapping("type", SINGLE_VALUED_FIELD_NAME, "type=keyword",
MULTI_VALUED_FIELD_NAME, "type=keyword",
"tag", "type=keyword").get());
List<IndexRequestBuilder> builders = new ArrayList<>();
for (int i = 0; i < 5; i++) {
builders.add(client().prepareIndex("idx", "type").setSource(
@ -163,7 +167,10 @@ public class StringTermsTests extends AbstractTermsTestCase {
bucketProps.put("sum_d", 1d);
expectedMultiSortBuckets.put((String) bucketProps.get("_term"), bucketProps);
createIndex("sort_idx");
assertAcked(client().admin().indices().prepareCreate("sort_idx")
.addMapping("type", SINGLE_VALUED_FIELD_NAME, "type=keyword",
MULTI_VALUED_FIELD_NAME, "type=keyword",
"tag", "type=keyword").get());
for (int i = 1; i <= 3; i++) {
builders.add(client().prepareIndex("sort_idx", "multi_sort_type").setSource(
jsonBuilder().startObject().field(SINGLE_VALUED_FIELD_NAME, "val1").field("l", 1).field("d", i).endObject()));

View File

@ -1,6 +1,15 @@
# Integration tests for using a scripted field
#
setup:
- do:
indices.create:
index: test
body:
mappings:
test:
properties:
foo:
type: keyword
- do:
index:
index: test

View File

@ -53,7 +53,7 @@ public class UpdateByQueryBasicTests extends UpdateByQueryTestCase {
// Limit with size
UpdateByQueryRequestBuilder request = request().source("test").size(3).refresh(true);
request.source().addSort("foo", SortOrder.ASC);
request.source().addSort("foo.keyword", SortOrder.ASC);
assertThat(request.get(), responseMatcher().updated(3));
// Only the first three documents are updated because of sort
assertEquals(4, client().prepareGet("test", "test", "1").get().getVersion());

View File

@ -19,7 +19,7 @@ setup:
script_fields:
bar:
script:
inline: "doc['foo'].value + x"
inline: "doc['foo.keyword'].value + x"
lang: javascript
params:
x: "bbb"

View File

@ -19,7 +19,7 @@ setup:
script_fields:
bar:
script:
inline: "doc['foo'].value + x"
inline: "doc['foo.keyword'].value + x"
lang: python
params:
x: "bbb"

View File

@ -19,6 +19,19 @@
- do:
cat.fielddata: {}
- do:
indices.create:
index: index
body:
settings:
number_of_shards: "1"
mappings:
type:
properties:
foo:
type: text
fielddata: true
- do:
index:
index: index

View File

@ -10,11 +10,13 @@ setup:
properties:
bar:
type: text
fielddata: true
fields:
completion:
type: completion
baz:
type: text
fielddata: true
fields:
completion:
type: completion

View File

@ -6,6 +6,14 @@
body:
settings:
number_of_shards: "1"
mappings:
doc:
properties:
text:
type: text
fielddata: true
class:
type: keyword
- do:
index:

View File

@ -24,6 +24,8 @@ setup:
"type" : "completion"
"suggest_6":
"type" : "completion"
title:
type: keyword
---
"Simple suggestion should work":