Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tystol opened this issue Nov 13, 2013 · 2 comments
Closed

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

tystol opened this issue Nov 13, 2013 · 2 comments

Comments

@tystol
Copy link

tystol commented Nov 13, 2013

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.

@Mpdreamz
Copy link
Member

Hi @ITS-TYSON

I rather write a special SuggestCompletion() mapping method for this but you are right that the it would be handy if you could make .Generic() not always write the name property.

@Mpdreamz
Copy link
Member

You can now pass an extra parameter that will prevent the name property to be outputted in the json:

https://github.com/Mpdreamz/NEST/blob/master/src/Nest.Tests.Unit/Core/Map/DynamicTemplates/DynamicTemplatesTests.cs?source=cc#L33

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants