Upgrading to Elastic Search NEST 7.0.1 breaks code that checks if an index exists

3.1k Views Asked by At

After upgrading Elastic Search NEST from 7.0.0-alpha2 to 7.0.1, I am no longer able to use the IndexExistsAsync method in Nest.ElasticClient.

According to the documentation, the method is removed and is a breaking change, so I changed the call to ElasticClient.Indices.ExistsAsync as follows:

Old code:

var existsResponse = await _elasticClient.IndexExistsAsync(model.Name);

New code:

var existsResponse = await _elasticClient.Indices.ExistsAsync(model.Name);

And with new code I get the following response, which is not really helpful in finding and fixing the issue:

Invalid NEST response built from a successful (404) low level call on HEAD: /12-e449636ee7e1eb1343414698c95ce1e1

Audit trail of this API call:
- [1] HealthyResponse: Node: http://localhost:9200/ Took: 00:00:00.1208228

Request:

Request stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.

Response:

Response stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.

Setting the connectionSettings.DisableDirectStreaming(true); did not help and I get the exact same response.

Any help is highly appreciated.

2

There are 2 best solutions below

3
Rob On

I think the message you see tells you everything.

Invalid NEST response built from a successful (404) low level call on HEAD: /12-e449636ee7e1eb1343414698c95ce1e1 

response built from a successful - elasticsearch call was successful, but status 404 (not exists) was returned and mapped to existsResponse.Exists which is false in this case. There is no additional request/response information attached, this is why you see:

Request:

Request stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.

Response:

Response stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.

Same behavior when you try to do it via kibana:

enter image description here

enter image description here

UPDATE:

When testing following code with elasticsearch 7.2.0 and NEST 7.0.1

var client = new ElasticClient(connectionSettings);              

await client.Indices.CreateAsync("documents");                   
var exists = await client.Indices.ExistsAsync("documents");      
Console.WriteLine($"Index created, exists?: {exists.Exists}");   

await client.Indices.DeleteAsync("documents");                   
exists = await client.Indices.ExistsAsync("documents");          
Console.WriteLine($"Index deleted, exists?: {exists.Exists}");   

prints

Index created, exists?: True
Index deleted, exists?: False

Hope that helps.

0
Marc On

The same problem here. After upgrade to Nest 7 (both 7.0.0 and 7.0.1) against an ElasticSearch cluster with version 7.2.0 we get the following message:

Invalid NEST response built from a unsuccessful (502) low level call on HEAD: /leads_2019.07

Audit trail of this API call:

  • [1] BadResponse: Node: http://xxx:9200/ Took: 00:00:00.1931249

    OriginalException: Elasticsearch.Net.ElasticsearchClientException: Request failed to execute. Call: Status code 502 from: HEAD /leads_2019.07

We get the same error against a cluster with version 6.8.1