0

I have the following property

[Nested] public List<TagModel> Tags { get; set; }

and in the TagModel there is a property as follows

[String] public string Tag { get; set; }

I would like to map the Tag property as a multi field property using Nest.

I thought this would work,

.String
    (s => s.Name
        (n => n.Tags.First()
            .Tag)
        .Fields
            (fi => fi.String
                (sub => sub.Name("partial")
                    .Analyzer("test"))
            .String
                (sub => sub.Name("middle")
                    .Analyzer("test2"))));

But in the mapping it outputs, Tags remains as:

"tags": {
    "type": "nested",
    "properties": {
        "tag": {
            "type": "string"
        },

and then at the end of the mapping:

"tags.tag": {
    "type": "string",
    "fields": {
        "partial": {
            "type": "string",
            "analyzer": "test",
        },
        "middle": {
            "type": "string",
            "analyzer": "test2",
        },

and throws a exception 400 saying reason": "Field name [tags.tag] cannot contain '.'"

I am guessing that it does not like the linq First() call in the name (which is odd as a search in a nested item does accept this....)

So how can I map a property in a class that is used in a property that is a nested item itself....

Currently using Nest 2.0.0 alpha-2

1 Answer 1

1

Ok, so after (alot of) guess and check, this can be done as follows:

x.Nested<TagModel>
    (ne => ne.Name(n => n.Tags)
        .AutoMap()
        .Properties
            (p => p.String
                    (s => s.Name(n => n.Tag)
                    .Fields
                        (fi => fi.String
                            (sub => sub.Name("partial")
                    .Analyzer("test"))
                .String
                    (sub => sub.Name("middle")
                    .Analyzer("test2"))))));

The AutoMap seems to be required when you have additional properties in the model, i.e. if I had like a TagID in the TagModel then without the AutoMap any additional properties not specifically mentioned here would not be mapped (even if they have the attributes etc setup).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.