Mapping: Allow to set index to `no` for _id and _type, closes #863.
This commit is contained in:
parent
c4be4975d6
commit
b94fab34eb
|
@ -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()
|
||||
|
|
|
@ -58,7 +58,7 @@ public class IdFieldMapper extends AbstractFieldMapper<String> 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<String> 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<String> implements org.el
|
|||
}
|
||||
context.id(id);
|
||||
context.parsedId(ParseContext.ParsedIdState.PARSED);
|
||||
if (index == Field.Index.NO && store == Field.Store.NO) {
|
||||
return null;
|
||||
}
|
||||
ArrayDeque<Field> cache = fieldCache.get();
|
||||
Field field = cache.poll();
|
||||
if (field == null) {
|
||||
|
@ -123,6 +126,9 @@ public class IdFieldMapper extends AbstractFieldMapper<String> 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<Field> cache = fieldCache.get();
|
||||
Field field = cache.poll();
|
||||
if (field == null) {
|
||||
|
@ -151,13 +157,16 @@ public class IdFieldMapper extends AbstractFieldMapper<String> 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;
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ public class TypeFieldMapper extends AbstractFieldMapper<String> 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<String> 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<String> implements org.
|
|||
}
|
||||
|
||||
@Override protected Field parseCreateField(ParseContext context) throws IOException {
|
||||
if (index == Field.Index.NO && store == Field.Store.NO) {
|
||||
return null;
|
||||
}
|
||||
ArrayDeque<Field> cache = fieldCache.get();
|
||||
Field field = cache.poll();
|
||||
if (field == null) {
|
||||
|
@ -132,13 +135,16 @@ public class TypeFieldMapper extends AbstractFieldMapper<String> 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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue