Why does the NEST library make a HEAD call every time?

I am using NEST library 6.5 from a .NET Core project. I've noticed that the library sends out an HTTP HEAD message prior to every call to get actual data.

HEAD http://10.50.136.80:9200/
GET http://10.50.136.80:9200/properties_web04/_search?typed_keys=true

What is the purpose of it? Can I turn it off?
The latency between client and the server ensures that every call I make is doubled in time.

NEST doesn't send a HEAD call every time.

Certain IConnectionPool implementations will ping a node on first usage or when a node is resurrected from having been previously marked as dead. You can turn off pinging by calling .DisablePing() on ConnectionSettings.

The purpose of pinging on first usage or when a node is resurrected is to perform a quick check to ensure a node is alive before performing potentially unneccessary work such as serializing a large bulk request and writing it to the request stream.

@Russ, I disagree that it only calls it on the first usage. See below, hitting ES from my website (screenshot from Fiddler). So it's definitely hitting it with HEAD every time.

Can you share details about how you are configuring ConnectionSettings? Also are you instantiating the client each time you call it, or creating a single instance and reusing?

Instantiating every time. Is that a wrong thing to do? I was following the same pattern as that for connecting to RDBMS databases.

That explains why you see a ping before each call :smile: The client is thread safe and a single instance is recommended.

1 Like

Ahh, ok. That explains it. Thank you. I imagined that there was a connection pool like an ODBC driver.

No worries :+1:

There's connection pooling in the BCL used by the client so that connections are reused, but the behaviour on top of this such as pinging, sniffing, caching of serialization components is part of the client code base. Take a look at the docs on connection pools for more details.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.