diff --git a/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/stress/SingleThreadBulkStress.java b/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/stress/SingleThreadBulkStress.java index 5ed678e0303..10d9c56fd17 100644 --- a/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/stress/SingleThreadBulkStress.java +++ b/modules/benchmark/micro/src/main/java/org/elasticsearch/benchmark/stress/SingleThreadBulkStress.java @@ -71,6 +71,8 @@ public class SingleThreadBulkStress { client1.admin().indices().prepareCreate("test").setSettings(settings).addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1") .startObject("_source").field("enabled", false).endObject() .startObject("_all").field("enabled", false).endObject() + .startObject("_type").field("index", "no").endObject() + .startObject("_id").field("index", "no").endObject() .startObject("properties") .startObject("field").field("type", "string").field("index", "not_analyzed").field("omit_norms", true).endObject() // .startObject("field").field("index", "analyzed").field("omit_norms", false).endObject() diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/IdFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/IdFieldMapper.java index 2ce0248e216..b6994aefe91 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/IdFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/IdFieldMapper.java @@ -58,7 +58,7 @@ public class IdFieldMapper extends AbstractFieldMapper implements org.el } @Override public IdFieldMapper build(BuilderContext context) { - return new IdFieldMapper(name, indexName, store, termVector, boost, omitNorms, omitTermFreqAndPositions); + return new IdFieldMapper(name, indexName, index, store, termVector, boost, omitNorms, omitTermFreqAndPositions); } } @@ -73,13 +73,13 @@ public class IdFieldMapper extends AbstractFieldMapper implements org.el } protected IdFieldMapper(String name, String indexName) { - this(name, indexName, Defaults.STORE, Defaults.TERM_VECTOR, Defaults.BOOST, + this(name, indexName, Defaults.INDEX, Defaults.STORE, Defaults.TERM_VECTOR, Defaults.BOOST, Defaults.OMIT_NORMS, Defaults.OMIT_TERM_FREQ_AND_POSITIONS); } - protected IdFieldMapper(String name, String indexName, Field.Store store, Field.TermVector termVector, + protected IdFieldMapper(String name, String indexName, Field.Index index, Field.Store store, Field.TermVector termVector, float boost, boolean omitNorms, boolean omitTermFreqAndPositions) { - super(new Names(name, indexName, indexName, name), Defaults.INDEX, store, termVector, boost, omitNorms, omitTermFreqAndPositions, + super(new Names(name, indexName, indexName, name), index, store, termVector, boost, omitNorms, omitTermFreqAndPositions, Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER); } @@ -112,6 +112,9 @@ public class IdFieldMapper extends AbstractFieldMapper implements org.el } context.id(id); context.parsedId(ParseContext.ParsedIdState.PARSED); + if (index == Field.Index.NO && store == Field.Store.NO) { + return null; + } ArrayDeque cache = fieldCache.get(); Field field = cache.poll(); if (field == null) { @@ -123,6 +126,9 @@ public class IdFieldMapper extends AbstractFieldMapper implements org.el if (context.id() == null) { throw new MapperParsingException("No id mapping with [" + names.name() + "] found in the content, and not explicitly set"); } + if (index == Field.Index.NO && store == Field.Store.NO) { + return null; + } ArrayDeque cache = fieldCache.get(); Field field = cache.poll(); if (field == null) { @@ -151,13 +157,16 @@ public class IdFieldMapper extends AbstractFieldMapper implements org.el @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { // if all are defaults, no sense to write it at all - if (store == Defaults.STORE) { + if (store == Defaults.STORE && index == Defaults.INDEX) { return builder; } builder.startObject(CONTENT_TYPE); if (store != Defaults.STORE) { builder.field("store", store.name().toLowerCase()); } + if (index != Defaults.INDEX) { + builder.field("index", index.name().toLowerCase()); + } builder.endObject(); return builder; } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/TypeFieldMapper.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/TypeFieldMapper.java index b6ee3ba36ed..865f647ab01 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/TypeFieldMapper.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/mapper/xcontent/TypeFieldMapper.java @@ -58,7 +58,7 @@ public class TypeFieldMapper extends AbstractFieldMapper implements org. } @Override public TypeFieldMapper build(BuilderContext context) { - return new TypeFieldMapper(name, indexName, store, termVector, boost, omitNorms, omitTermFreqAndPositions); + return new TypeFieldMapper(name, indexName, index, store, termVector, boost, omitNorms, omitTermFreqAndPositions); } } @@ -73,13 +73,13 @@ public class TypeFieldMapper extends AbstractFieldMapper implements org. } protected TypeFieldMapper(String name, String indexName) { - this(name, indexName, Defaults.STORE, Defaults.TERM_VECTOR, Defaults.BOOST, + this(name, indexName, Defaults.INDEX, Defaults.STORE, Defaults.TERM_VECTOR, Defaults.BOOST, Defaults.OMIT_NORMS, Defaults.OMIT_TERM_FREQ_AND_POSITIONS); } - public TypeFieldMapper(String name, String indexName, Field.Store store, Field.TermVector termVector, + public TypeFieldMapper(String name, String indexName, Field.Index index, Field.Store store, Field.TermVector termVector, float boost, boolean omitNorms, boolean omitTermFreqAndPositions) { - super(new Names(name, indexName, indexName, name), Defaults.INDEX, store, termVector, boost, omitNorms, omitTermFreqAndPositions, + super(new Names(name, indexName, indexName, name), index, store, termVector, boost, omitNorms, omitTermFreqAndPositions, Lucene.KEYWORD_ANALYZER, Lucene.KEYWORD_ANALYZER); } @@ -109,6 +109,9 @@ public class TypeFieldMapper extends AbstractFieldMapper implements org. } @Override protected Field parseCreateField(ParseContext context) throws IOException { + if (index == Field.Index.NO && store == Field.Store.NO) { + return null; + } ArrayDeque cache = fieldCache.get(); Field field = cache.poll(); if (field == null) { @@ -132,13 +135,16 @@ public class TypeFieldMapper extends AbstractFieldMapper implements org. @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { // if all are defaults, no sense to write it at all - if (store == Defaults.STORE) { + if (store == Defaults.STORE && index == Defaults.INDEX) { return builder; } builder.startObject(CONTENT_TYPE); if (store != Defaults.STORE) { builder.field("store", store.name().toLowerCase()); } + if (index != Defaults.INDEX) { + builder.field("index", index.name().toLowerCase()); + } builder.endObject(); return builder; }