2

I am trying to add a new property to an existing nested document. My document looks like:

"mappings": {
  "test": {
    "_routing": {
      "required": true,
      "path": "tId"
    },
    "properties": {

      "series": {
        "type": "nested",
        "properties": {

          "iType": {
            "type": "string",
            "index": "not_analyzed",
            "doc_values": true
          },
          "isValid": {
            "type": "boolean"
          },

        },
      },
    }
  }

The property i want to insert to nested document "series" is "iType". How can i use the NEST put mapping API to update the existing mapping?

Any help will be appreciated.

Thanks in advance.

#####*****UPDATED*****##########

i would need to update the mapping for nested element with attributes :

"iType": {
  "type": "string",
  "fields": {
    "raw": {
      "type": "string",
      "index": "not_analyzed",
      "doc_values": true,
      "fielddata": {
        "loading": "eager_global_ordinals"
      }
    }
  }
},

How can i do this with NEST ?

My query looks like:

var response2 = elasticClient.Map < Test > (e => e
  .Properties(props => props
    .NestedObject < series > (s => s
      .Properties(sprops => sprops
        .String(n => n.Name(name => "iType"))))));

i get an exception: Could not get field name for nested sobject mapping Any corrections to be made in query?

1 Answer 1

4

You can update mapping for nested object by

var response = client.Map<YourType>(m => m
    .Properties(p => p
        .NestedObject<YourNestedType>(n => n
            .Name(name => name.NestedObject)
            .Properties(pp => pp
                .String(s => s.Name(name => name.NewProp))
            ))));

update

This is how you can update your index mapping with multi fields:

var response = client.Map<Test>(m => m
    .Properties(p => p
        .NestedObject<Series>(nested => nested
            .Name(name => name.Series)
            .Properties(pp => pp
                .MultiField(mf => mf
                    .Name(name => name.iType)
                    .Fields(f => f 
                        .String(s => s.Name(n => n.iType))
                        .String(s => s
                            .Name(n => n.iType.Suffix("raw"))
                            .Index(FieldIndexOption.NotAnalyzed)
                            .DocValues()
                            .FieldData(fd => fd
                                .Loading(FieldDataLoading.EagerGlobalOrdinals))))))
            ))); 

You got the exception, because you didn't specify name for nested object, take a look one more time at my mapping definition: enter image description here

Hope it helps.

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

2 Comments

thanks for the answer. I have updated the question. I need to add raw attribute to the property. How can this be done?
i need to add a new property called "IType" with attributes "raw" as mentioned in the updated part of the question.

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.