0
votes

I have an elasticsearch index with mappings like the following:

{
  "indexName": {
    "mappings": {
      "vault": {
        "properties": {
          "someMapping": {
            "dynamic": "true",
            "properties": {
              "A": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "B": {
                "type": "float"
              },
              "C": {
                "type": "float"
              }
            }
          }
        }
      }
    }
  }
}

I need to get the nested mappings' types, for example:

   [
     {Name = "A", Type = "text"},
     {Name = "B", Type = "float"},
     {Name = "C", Type = "float"}
    ]

I need this to happen trough NEST API in .NET Core application. So far I've tried elasticClient.GetMapping(new GetMappingRequest()) with not much success since I cannot access the nested properties of the field I need (in this example "someMapping")

1

1 Answers

0
votes

I was able to achieve what I wanted by the following steps:

  • Get the mappings for all the indices in the elastic search instance by: allIndicesMappings = elasticClient.GetMapping(new GetMappingRequest()).Mappings
  • Filter the indices that you want by name (optional)
  • For each of the items in the filtered list you can get the field you want like so: item.Value.FirstOrDefault().Value.Properties.FirstOrDefault(x => x.Key.Name == "someMapping").Value That returns the someMapping field, but still we don't have access to it's nested properties. That access we can get by casting it to ObjectProperty like so: ((ObjectProperty)item.Value.FirstOrDefault().Value.Properties.FirstOrDefault(x => x.Key.Name == "metadata").Value).Properties In the Properties now we have the nested fields and their mappings