How to get exsiting display in ElasticSearch index
Using Nest and C #, I would like to examine the mapping present in the index.
var settings = new ConnectionSettings(new Uri("http://localhost:9200"));
var client = new ElasticClient(settings);
var status = client.Status();
This will return the available ES server indexes. But I would also like to know what types are displayed in these indices. I tried using:
var mapping = client.GetMapping(???);
But these methods and overloads seem to need a display name. This is exactly what I am trying to figure out. I cannot find the correct documentation for this situation.
source to share
You can use either overloading to pull the mapping for a specific index / type (but these are not multiple indexes or types currently)
client.GetMapping(g => g.Index("myindex").Type("mytype")));
against
client.GetMapping(new GetMappingRequest {Index = "myindex", Type = "mytype"});
I can't be sure what happens when you implicitly put <object>
(it might explode, I'm not on a Windows machine to test it), but you obviously don't know the type ( T
) to put in there and need something.
Unfortunately, the current limit with the above (assuming it works with <object>
) is that you have to specify Index
and optionally it Type
. If you don't specify Type
, but Index
contains more than one type, then it will simply select the first one to be returned. And I doubt this is what you want, so I created an issue for it on GitHub after discussing with Greg (one of the NEST developers).
Fortunately, there is always a fallback in NEST that has to move to the lower level Elasticsearch.NET APIs. There you can make your request IndicesGetMapping
. An overview of the generated tests can be found here which will probably help you better understand it for the generated query.
var response = client.IndicesGetMapping("test_1,test_2");
// Deserialized JSON:
//
// response.test_1.mappings.type_1.properties
// response.test_1.mappings.type_2.properties
// response.test_2.mappings.type_a.properties
Note. You can also use these overloads:
// First parameter is indices (comma separated, potentially wildcarded list)
// _all is a special placeholder to [shockingly] specify all
var response = client.IndicesGetMapping("_all", "_all");
var response = client.IndicesGetMapping("index1,index2", "_all");
// Enjoy the loops:
var response = client.IndicesGetMappingForAll();
This can be found inIElasticsearchClient.Generated
(huge file, so search for IndicesGetMapping
").
source to share