honor the enabled=false flag at the top-level of doc mapping
fixes #331
This commit is contained in:
parent
f0d6abff6f
commit
96577606c3
@ -402,13 +402,15 @@ func (im *IndexMapping) mapDocument(doc *document.Document, data interface{}) er
|
||||
docType := im.determineType(data)
|
||||
docMapping := im.mappingForType(docType)
|
||||
walkContext := im.newWalkContext(doc, docMapping)
|
||||
docMapping.walkDocument(data, []string{}, []uint64{}, walkContext)
|
||||
if docMapping.Enabled {
|
||||
docMapping.walkDocument(data, []string{}, []uint64{}, walkContext)
|
||||
|
||||
// see if the _all field was disabled
|
||||
allMapping := docMapping.documentMappingForPath("_all")
|
||||
if allMapping == nil || (allMapping.Enabled != false) {
|
||||
field := document.NewCompositeFieldWithIndexingOptions("_all", true, []string{}, walkContext.excludedFromAll, document.IndexField|document.IncludeTermVectors)
|
||||
doc.AddField(field)
|
||||
// see if the _all field was disabled
|
||||
allMapping := docMapping.documentMappingForPath("_all")
|
||||
if allMapping == nil || (allMapping.Enabled != false) {
|
||||
field := document.NewCompositeFieldWithIndexingOptions("_all", true, []string{}, walkContext.excludedFromAll, document.IndexField|document.IncludeTermVectors)
|
||||
doc.AddField(field)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -402,3 +402,22 @@ func TestMappingBool(t *testing.T) {
|
||||
t.Errorf("expected to find 2 fields, found %d", count)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDisableDefaultMapping(t *testing.T) {
|
||||
indexMapping := NewIndexMapping()
|
||||
indexMapping.DefaultMapping.Enabled = false
|
||||
|
||||
data := map[string]string{
|
||||
"name": "bleve",
|
||||
}
|
||||
|
||||
doc := document.NewDocument("x")
|
||||
err := indexMapping.mapDocument(doc, data)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(doc.Fields) > 0 {
|
||||
t.Errorf("expected no fields, got %d", len(doc.Fields))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user