include_in_all not overridable in objects, closes #883.
This commit is contained in:
parent
5c8fe598a6
commit
19448d7775
|
@ -25,4 +25,6 @@ package org.elasticsearch.index.mapper.xcontent;
|
|||
public interface IncludeInAllMapper extends XContentMapper {
|
||||
|
||||
void includeInAll(Boolean includeInAll);
|
||||
|
||||
void includeInAllIfNotSet(Boolean includeInAll);
|
||||
}
|
||||
|
|
|
@ -171,6 +171,12 @@ public class MultiFieldMapper implements XContentMapper, IncludeInAllMapper {
|
|||
}
|
||||
}
|
||||
|
||||
@Override public void includeInAllIfNotSet(Boolean includeInAll) {
|
||||
if (includeInAll != null && defaultMapper != null && (defaultMapper instanceof IncludeInAllMapper)) {
|
||||
((IncludeInAllMapper) defaultMapper).includeInAllIfNotSet(includeInAll);
|
||||
}
|
||||
}
|
||||
|
||||
public ContentPath.Type pathType() {
|
||||
return pathType;
|
||||
}
|
||||
|
|
|
@ -107,6 +107,12 @@ public abstract class NumberFieldMapper<T extends Number> extends AbstractFieldM
|
|||
}
|
||||
}
|
||||
|
||||
@Override public void includeInAllIfNotSet(Boolean includeInAll) {
|
||||
if (includeInAll != null && this.includeInAll == null) {
|
||||
this.includeInAll = includeInAll;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract int maxPrecisionStep();
|
||||
|
||||
public int precisionStep() {
|
||||
|
|
|
@ -119,7 +119,7 @@ public class ObjectMapper implements XContentMapper, IncludeInAllMapper {
|
|||
context.path().pathType(origPathType);
|
||||
context.path().remove();
|
||||
|
||||
objectMapper.includeInAll(includeInAll);
|
||||
objectMapper.includeInAllIfNotSet(includeInAll);
|
||||
|
||||
return (Y) objectMapper;
|
||||
}
|
||||
|
@ -252,9 +252,21 @@ public class ObjectMapper implements XContentMapper, IncludeInAllMapper {
|
|||
}
|
||||
}
|
||||
|
||||
@Override public void includeInAllIfNotSet(Boolean includeInAll) {
|
||||
if (this.includeInAll == null) {
|
||||
this.includeInAll = includeInAll;
|
||||
}
|
||||
// when called from outside, apply this on all the inner mappers
|
||||
for (XContentMapper mapper : mappers.values()) {
|
||||
if (mapper instanceof IncludeInAllMapper) {
|
||||
((IncludeInAllMapper) mapper).includeInAllIfNotSet(includeInAll);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ObjectMapper putMapper(XContentMapper mapper) {
|
||||
if (mapper instanceof IncludeInAllMapper) {
|
||||
((IncludeInAllMapper) mapper).includeInAll(includeInAll);
|
||||
((IncludeInAllMapper) mapper).includeInAllIfNotSet(includeInAll);
|
||||
}
|
||||
synchronized (mutex) {
|
||||
mappers = newMapBuilder(mappers).put(mapper.name(), mapper).immutableMap();
|
||||
|
|
|
@ -110,6 +110,12 @@ public class StringFieldMapper extends AbstractFieldMapper<String> implements In
|
|||
}
|
||||
}
|
||||
|
||||
@Override public void includeInAllIfNotSet(Boolean includeInAll) {
|
||||
if (includeInAll != null && this.includeInAll == null) {
|
||||
this.includeInAll = includeInAll;
|
||||
}
|
||||
}
|
||||
|
||||
@Override public String value(Fieldable field) {
|
||||
return field.stringValue();
|
||||
}
|
||||
|
|
|
@ -44,7 +44,8 @@ public class SimpleAllMapperTests {
|
|||
Document doc = docMapper.parse(json).doc();
|
||||
AllField field = (AllField) doc.getFieldable("_all");
|
||||
AllEntries allEntries = ((AllTokenStream) field.tokenStreamValue()).allEntries();
|
||||
assertThat(allEntries.fields().size(), equalTo(2));
|
||||
assertThat(allEntries.fields().size(), equalTo(3));
|
||||
assertThat(allEntries.fields().contains("address.last.location"), equalTo(true));
|
||||
assertThat(allEntries.fields().contains("name.last"), equalTo(true));
|
||||
assertThat(allEntries.fields().contains("simple1"), equalTo(true));
|
||||
}
|
||||
|
@ -61,7 +62,8 @@ public class SimpleAllMapperTests {
|
|||
|
||||
AllField field = (AllField) doc.getFieldable("_all");
|
||||
AllEntries allEntries = ((AllTokenStream) field.tokenStreamValue()).allEntries();
|
||||
assertThat(allEntries.fields().size(), equalTo(2));
|
||||
assertThat(allEntries.fields().size(), equalTo(3));
|
||||
assertThat(allEntries.fields().contains("address.last.location"), equalTo(true));
|
||||
assertThat(allEntries.fields().contains("name.last"), equalTo(true));
|
||||
assertThat(allEntries.fields().contains("simple1"), equalTo(true));
|
||||
}
|
||||
|
|
|
@ -1,13 +1,22 @@
|
|||
{
|
||||
"person" : {
|
||||
"_all" : {"enabled" : true},
|
||||
"_all" : {
|
||||
"enabled" : true
|
||||
},
|
||||
"properties" : {
|
||||
"name" : {
|
||||
"type" : "object",
|
||||
"dynamic" : false,
|
||||
"properties" : {
|
||||
"first" : {"type" : "string", "store" : "yes", "include_in_all" : false},
|
||||
"last" : {"type" : "string", "index" : "not_analyzed"}
|
||||
"first" : {
|
||||
"type" : "string",
|
||||
"store" : "yes",
|
||||
"include_in_all" : false
|
||||
},
|
||||
"last" : {
|
||||
"type" : "string",
|
||||
"index" : "not_analyzed"
|
||||
}
|
||||
}
|
||||
},
|
||||
"address" : {
|
||||
|
@ -16,18 +25,31 @@
|
|||
"properties" : {
|
||||
"first" : {
|
||||
"properties" : {
|
||||
"location" : {"type" : "string", "store" : "yes", "index_name" : "firstLocation"}
|
||||
"location" : {
|
||||
"type" : "string",
|
||||
"store" : "yes",
|
||||
"index_name" : "firstLocation"
|
||||
}
|
||||
}
|
||||
},
|
||||
"last" : {
|
||||
"properties" : {
|
||||
"location" : {"type" : "string"}
|
||||
"location" : {
|
||||
"type" : "string",
|
||||
"include_in_all" : true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"simple1" : {"type" : "long", "include_in_all" : true},
|
||||
"simple2" : {"type" : "long", "include_in_all" : false}
|
||||
"simple1" : {
|
||||
"type" : "long",
|
||||
"include_in_all" : true
|
||||
},
|
||||
"simple2" : {
|
||||
"type" : "long",
|
||||
"include_in_all" : false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue