IElasticClient.CatHealth() works OK locally, but fails in json parsing when talking to elastic cloud instance

Hi gang,

Context:
ElasticSearch 2.3.4
C#/.Net apps using NEST & Elasticsearch.Net 2.3.3 (next hop is of client nuget package is to 2.4.x which forces us to upgrade Newtonsoft.Json, so I'd like to avoid that if possible for now).

I have ES 2.3.4 running locally and have a suite of integration tests covering functionality leveraged by our application. All tests are passing nicely.

We're now getting ready to take the cloud-hosted step, so I set up a trial account for elastic cloud, created a cluster (also 2.3.4), set the access creds configuration (left at defaults that were generated), and then configured and aimed our tests at the new cloud-hosted cluster...

... all my indexing and search-based tests are still passing nicely.. but anything that tries to call the "Cat*"-related methods (eg. IElasticClient.CatHealth()) is failing with exceptions like this:

Result Message:
Test method IntegrationTests.ElasticSearchFtsTests.That_Cluster_Is_Accessible threw exception:
Elasticsearch.Net.UnexpectedElasticsearchClientException: Error converting value 1468428886 to type 'System.Collections.Generic.IEnumerable1[Nest.CatHealthRecord]'. Path '', line 1, position 10. ---> Newtonsoft.Json.JsonSerializationException: Error converting value 1468428886 to type 'System.Collections.Generic.IEnumerable1[Nest.CatHealthRecord]'. Path '', line 1, position 10. ---> System.ArgumentException: Could not cast or convert from System.Int64 to System.Collections.Generic.IEnumerable`1[Nest.CatHealthRecord].

... the same client code, same ES server version handles the result fine when run locally, but barfs trying to parse the results from "_cat/health" when aimed at the hosted cluster.. the results of _cat/health (via Sense) look comparable in both cases and are definitely not Json... so why it's being parsed as Json is a mystery, and understandable that the parsing is failing... but why is this handled gracefully in the local hosting scenario and not in the cloud hosted scenario?

Thanks for your help,

Tyler

Hi Tyler,
this seems to be a problem around headers being filtered out by Elastic Cloud. There's also an issue opened for it: https://github.com/elastic/elasticsearch-net/issues/2076 . We are discussing a fix for this, you can track progress on the issue that I posted.

Cheers
Luca

1 Like

Hi this is a known issue:

Elastic Cloud strips the accept header and NEST wants the cat data in json form.

You can use the lowlevel cat API instead to circumvent the problem

var client = new ElasticClient(new Uri("http://localhost:9200"));
var catHealth = client.LowLevel.CatHealth<string>();
//catHealth.Body will hold the string as returned by default by elasticsearch

or just use the .ClusterHealth() endpoint to get the same information in a more typed fashion

var clusterHealth = client.ClusterHealth();
1 Like

Hi Martijn, thanks for the response. Your workaround is what had fallen back to and it is working nicely. Thanks again,

Tyler