3

I want to check the discrepancies between my current mapping (as in my C# code) and the mapping in the elasticsearch index.

With only:

var res = esClient.GetMapping<EsCompany>();

I get GetMappingResponse object in c#, I will have to compare field by field for equality. Even worse, each field has their own properties, I have to descend into those properties for further comparison.

In my application, I prefer obtaining the raw json of the mapping, and I can easily diff two json objects for equality.

I then tried this:

var res = esClient.Raw.IndicesGetMapping(myIndexName);

But when I read res.Response, I get an AmbiguousMatchException exception.

Frederik Struck-Schøning
  • 12,981
  • 8
  • 59
  • 68
foresightyj
  • 2,006
  • 2
  • 26
  • 40

1 Answers1

5

When you connect to Elasticsearch you can choose to expose the raw response like this:

var client = new ElasticClient(new ConnectionSettings().ExposeRawResponse());

Then you should be able to access the raw json via:

var json = res.ConnectionStatus.ResponseRaw;
Frederik Struck-Schøning
  • 12,981
  • 8
  • 59
  • 68
modec
  • 213
  • 1
  • 9
  • I never thought about this. I spent some time going through all methods in ConnectionSettings and learned a few others I didn't know of. Thanks a lot! – foresightyj Jul 26 '15 at 02:36
  • 1
    I have a somewhat related question. I need to compare the mapping of the index in the elasticsearch server with the mapping defined in my code. But I can only create an index (via `CreateIndex`) with the new mapping first and then read the json mapping from there. Is there a way to get the Json mapping without actually creating an index? – foresightyj Aug 05 '15 at 06:55
  • @foresightyj, yes - serialize the create index descriptor with NEST's serializer to get the json without needing to make a request. – Russ Cam May 31 '16 at 07:43
  • 2
    Is `.ExposeRawResponse()` still available? Because I don't see it. – abdul qayyum Mar 28 '18 at 10:31