Fix include_in_all for multi field, to not include multi fields into _all field.
Closes #5522
This commit is contained in:
parent
89a48014f0
commit
0ee889fd8b
|
@ -156,6 +156,7 @@ public class ParseContext {
|
||||||
private boolean mappingsModified = false;
|
private boolean mappingsModified = false;
|
||||||
private boolean withinNewMapper = false;
|
private boolean withinNewMapper = false;
|
||||||
private boolean withinCopyTo = false;
|
private boolean withinCopyTo = false;
|
||||||
|
private boolean withinMultiFields = false;
|
||||||
|
|
||||||
private boolean externalValueSet;
|
private boolean externalValueSet;
|
||||||
|
|
||||||
|
@ -237,6 +238,14 @@ public class ParseContext {
|
||||||
return withinCopyTo;
|
return withinCopyTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setWithinMultiFields() {
|
||||||
|
this.withinMultiFields = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearWithinMultiFields() {
|
||||||
|
this.withinMultiFields = false;
|
||||||
|
}
|
||||||
|
|
||||||
public String index() {
|
public String index() {
|
||||||
return this.index;
|
return this.index;
|
||||||
}
|
}
|
||||||
|
@ -360,6 +369,9 @@ public class ParseContext {
|
||||||
if (withinCopyTo) {
|
if (withinCopyTo) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (withinMultiFields) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (!docMapper.allFieldMapper().enabled()) {
|
if (!docMapper.allFieldMapper().enabled()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -911,6 +911,8 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.setWithinMultiFields();
|
||||||
|
|
||||||
ContentPath.Type origPathType = context.path().pathType();
|
ContentPath.Type origPathType = context.path().pathType();
|
||||||
context.path().pathType(pathType);
|
context.path().pathType(pathType);
|
||||||
|
|
||||||
|
@ -920,6 +922,8 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T> {
|
||||||
}
|
}
|
||||||
context.path().remove();
|
context.path().remove();
|
||||||
context.path().pathType(origPathType);
|
context.path().pathType(origPathType);
|
||||||
|
|
||||||
|
context.clearWithinMultiFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
// No need for locking, because locking is taken care of in ObjectMapper#merge and DocumentMapper#merge
|
// No need for locking, because locking is taken care of in ObjectMapper#merge and DocumentMapper#merge
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.elasticsearch.common.lucene.all.AllTermQuery;
|
||||||
import org.elasticsearch.common.lucene.all.AllTokenStream;
|
import org.elasticsearch.common.lucene.all.AllTokenStream;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||||
import org.elasticsearch.index.mapper.FieldMapper;
|
import org.elasticsearch.index.mapper.FieldMapper;
|
||||||
|
@ -40,6 +41,7 @@ import org.elasticsearch.test.ElasticsearchTestCase;
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -280,4 +282,24 @@ public class SimpleAllMapperTests extends ElasticsearchTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMultiField() throws IOException {
|
||||||
|
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/all/multifield-mapping.json");
|
||||||
|
DocumentMapper docMapper = MapperTestUtils.newParser().parse(mapping);
|
||||||
|
|
||||||
|
XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||||
|
builder.startObject()
|
||||||
|
.field("_id", "1")
|
||||||
|
.field("foo")
|
||||||
|
.startObject()
|
||||||
|
.field("bar", "Elasticsearch rules!")
|
||||||
|
.endObject()
|
||||||
|
.endObject();
|
||||||
|
|
||||||
|
Document doc = docMapper.parse(builder.bytes()).rootDoc();
|
||||||
|
AllField field = (AllField) doc.getField("_all");
|
||||||
|
AllEntries allEntries = ((AllTokenStream) field.tokenStream(docMapper.mappers().indexAnalyzer())).allEntries();
|
||||||
|
assertThat(allEntries.fields(), empty());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
{
|
||||||
|
"test": {
|
||||||
|
"properties": {
|
||||||
|
"foo": {
|
||||||
|
"type": "nested",
|
||||||
|
"include_in_all": false,
|
||||||
|
"properties": {
|
||||||
|
"bar": {
|
||||||
|
"type": "string",
|
||||||
|
"index": "not_analyzed",
|
||||||
|
"include_in_all": false,
|
||||||
|
"fields": {
|
||||||
|
"lower": {
|
||||||
|
"analyzer": "standard",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue