NEST (C#) How to disable any automatic mapping and ensure only manually coded fields added to index

I have a mapping with fluent syntaxis where I carefully set only those fields I need. However when I add document to those index, i still see all fields from the object except thouse, who I manually add to ingore.

I don't really call something similar to.Automap() anywhere but it looks like it's a defult behaviour. How could I disable it and let only selected fields come to index, instead of all of them?

You need to specify the dynamic setting in your Index mapping. If you set it to false all fields not defined in the mapping will be silently ignored while if you set it to strict an exception is raised and the document fail to be indexed. See dynamic Mapping parameter.

@Bernt_Rostad is correct. You can set this behaviour in NEST when creating the index

var createIndexResponse = client.CreateIndex("my_index", c => c
    .Mappings(m => m
        .Map<MyDocument>(mm => mm
            .Dynamic(false)
        )
    )
);

or if the index already exists

var putMappingResponse = client.Map<MyDocument>(m => m
    .Index("my_index")
    .Dynamic(false)
)

@forloop @Bernt_Rostad Thanks a lot

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.