I\'m using the NEST library to interact with ElasticSearch, and I\'m trying to figure out a way to build index types/nested objects based on non-type data. The type has the
If I understand correctly your intention, Entity
object will have only nested objects in it, won't it?
You can try to use dynamic mapping functionality of elasticsearch for entity object. I assume Entity is a root object.
curl -X POST localhost:9200/myindex/entity/_mapping
{"dynamic_templates": [
{"nested_data_template": {
"mapping": {
"type": "nested" },
"match_mapping_type": "object",
"path_match": "*" }}]}
path_match: *
and match_mapping_type: object
mean that for all field names with object as a value nested type mapping will be applied.
Using NEST and Fluent API you can use the following API. IntelliSense will guide you how to build mapping above. ;)
descriptor.DynamicTemplates(DynamicTemplatesDescriptor<Entity>)
Every time when a new property matching this template appears, elasticsearch will update mapping based on dynamic mapping. After a while your mapping will look like:
{
"entity": {
"mappings": {
"entity": {
"dynamic_templates": [
{
"nested_data_template": {
"mapping": {
"type": "nested"
},
"match_mapping_type": "object",
"path_match": "*"
}
}
],
"properties": {
"test": {
"type": "nested",
"properties": {
"test": {
"type": "string"
},
"another_property": {
"type": "string"
}
}
},
"test1": {
"type": "nested",
"properties": {
"test": {
"type": "string"
}
}
}
}
}
}
}
}
Hope this will help!