4

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.

Milad Ghafoori
  • 310
  • 2
  • 14

2 Answers2

1

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.

Rob
  • 9,664
  • 3
  • 41
  • 43
  • As you correctly pointed out, the HTTP Response from ES tells me that the index does not exist (404). What I did not mention in my question was that the rest of my code relies on a properly populated NEST response object and I check for the IsValid property to continue with index creation or return. And in cases where the index exists, I still get an IsValid=false and Exists=false. It seems that the 7.0.1 clients (both high level and low level) do not populate the response object correctly and ES needs to fix them. – Milad Ghafoori Jul 07 '19 at 14:44
  • Oh, I see what you mean. Just tested it with NEST 7.0.1 and still works correctly. Are you sure you are using NEST 7.x against elasticsearch 7.x? – Rob Jul 07 '19 at 14:55
  • I am using NEST 7.0.1 against a local docker container of ElasticSearch 7.2.0. The code you provided works, but not when I reverse the order and first run the ExistsAsync! – Milad Ghafoori Jul 09 '19 at 01:25
0

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

Marc
  • 23
  • 3