Fix include_in_all for multi field, to not include multi fields into _all field.

Closes #5522
This commit is contained in:
Kevin Wang 2014-03-25 15:15:51 +11:00 committed by Martijn van Groningen
parent 89a48014f0
commit 0ee889fd8b
4 changed files with 61 additions and 0 deletions

View File

@ -156,6 +156,7 @@ public class ParseContext {
private boolean mappingsModified = false;
private boolean withinNewMapper = false;
private boolean withinCopyTo = false;
private boolean withinMultiFields = false;
private boolean externalValueSet;
@ -237,6 +238,14 @@ public class ParseContext {
return withinCopyTo;
}
public void setWithinMultiFields() {
this.withinMultiFields = true;
}
public void clearWithinMultiFields() {
this.withinMultiFields = false;
}
public String index() {
return this.index;
}
@ -360,6 +369,9 @@ public class ParseContext {
if (withinCopyTo) {
return false;
}
if (withinMultiFields) {
return false;
}
if (!docMapper.allFieldMapper().enabled()) {
return false;
}

View File

@ -911,6 +911,8 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T> {
return;
}
context.setWithinMultiFields();
ContentPath.Type origPathType = context.path().pathType();
context.path().pathType(pathType);
@ -920,6 +922,8 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T> {
}
context.path().remove();
context.path().pathType(origPathType);
context.clearWithinMultiFields();
}
// No need for locking, because locking is taken care of in ObjectMapper#merge and DocumentMapper#merge

View File

@ -31,6 +31,7 @@ import org.elasticsearch.common.lucene.all.AllTermQuery;
import org.elasticsearch.common.lucene.all.AllTokenStream;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.FieldMapper;
@ -40,6 +41,7 @@ import org.elasticsearch.test.ElasticsearchTestCase;
import org.hamcrest.Matchers;
import org.junit.Test;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
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());
}
}

View File

@ -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"
}
}
}
}
}
}
}
}