Reputation: 536
Currently, I can retrieve the index mapping metadata from the following command on Kibana
GET /[indexName]/_mapping/[documentType]
Is there a way to do that on Elasticsearch Nest Client? If not, what other options would I have?
Upvotes: 0
Views: 1288
Reputation: 125528
You can retrieve it with
var defaultIndex = "default-index";
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var settings = new ConnectionSettings(pool)
.DefaultIndex(defaultIndex);
var client = new ElasticClient(settings);
var mappingResponse = client.GetMapping<MyDocument>();
which will send a request to
GET http://localhost:9200/default-index/_mapping/mydocument
In this case
index
will be "default-index"
, the default index configured on Connection Settingstype
will be "mydocument"
, inferred from the POCO type MyDocument
You can specify index and/or type explicitly if you want to
var mappingResponse = client.GetMapping<MyDocument>(m => m
.Index("foo")
.Type("bar")
);
which sends the following request
GET http://localhost:9200/foo/_mapping/bar
As well as target all indices and/or all types
var mappingResponse = client.GetMapping<MyDocument>(m => m
.AllIndices()
.AllTypes()
);
which sends the following request
GET http://localhost:9200/_mapping
Upvotes: 1