Skip to content

Repeating field 'name' property as child property can cause errors #384

Closed
@tystol

Description

@tystol

NEST always repeats the field name within the field properties when using fluent mapping. e.g. in the below PUT mapping 'title' is repeated as the json member name within the 'properties' object, and also as the value for the 'name' member of itself.

{
    "mydoctype": {
        "properties": {
            "title": {
                "type": "string",
                "name": "title",
                "index": "not_analyzed"
            },
        }
    }
}

This is fine for most cases, but breaks down in edge cases. I'm trying to setup completion suggest fields (using the fluent mapping Generic, until this PR is merged), and the 'name' field doesnt exist on it.

e.g:

.MultiField(mf => mf
    .Name(d => d.Title)
        .Fields(f => f
            .String(s => s.Name(d => d.Title))
            .Generic(s => s
                .Type("completion")
                .Name("suggest")
                .IndexAnalyzer("default"))))

produces the following, which fails ({"error":"MapperParsingException[Unknown field [name]]","status":400}):

{
    "mydoctype": {
        "properties": {
            "title": {
                "type": "multi_field",
                "fields": {
                    "title": {
                        "type": "string"
                    },
                    "suggest": {
                        "name": "suggest",
                        "type": "completion",
                        "index_analyzer": "default"
                    }
                }
            }
        }
    }
}

Removing the "name": "suggest", part manually (using fiddler edit and replay) it then succeeds.

I tried looking into the source code to fix it myself (I was thinking a config option somewhere to turn this behaviour off), but I have no idea where to start. Any pointers appreciated! If there's already an option for this, my apologies, I did look but couldn't find it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions