ropensci / elastic

R client for the Elasticsearch HTTP API
https://docs.ropensci.org/elastic
Other
245 stars 58 forks source link

unnecessary multiple ping() calls to get ES version #184

Closed henfiber closed 6 years ago

henfiber commented 7 years ago

Hello there. After profiling some ES queries, I noticed that the minimum request time was about 300 milliseconds and found out that this is in large (the 200ms, about 65%) due to the multiple ping()$version$number checks in search_POST() and search_GET(). You may have not noticed it during development with a local server, but makes a large difference when ES is behind a distant network. (In my use case, each ping() roundtrip takes about 80-110 ms)

e.g. at search.r and Search_uri.R

# in ES >= v5, lenient param droppped
if (gsub("\\.", "", ping()$version$number) >= 500) args$lenient <- NULL
# in ES >= v5, fields param changed to stored_fields
if (gsub("\\.", "", ping()$version$number) >= 500) { ... }

the second ping() call could be saved by saving the result of the first call. Or probably totally avoided if the version is cached in the session variables during the first ping() call in that session (should be invalidated after a next connect() call, since the server and version may be different).

sckott commented 6 years ago

thanks for the issue @henfiber

Right, i probably didn't notice due to testing on local server instance.

I'll cache the ES version and reuse it

henfiber commented 6 years ago

thanks @sckott much appreciated