Prevent double calls to search.execute! when also querying shards, aggregations, and suggestions' #847
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was noticing a ton of duplicate search logs in my app, and tracked it down to the
Response.response
method running asearch.execute!
in which theraw_response
is not being saved, causing subsequent calls to queryshards
,aggregations
, andsuggestions
to perform anothersearch.execute!
. call An example of when this might occur is the followingBy simply storing the
search.execute!
return in the@raw_response
var, we can utilize the cachedraw_response
in the subsequent calls and prevent double searches.I have submitted 2 pull requests prior to this one that ended up having pitfalls so I closed them. After some more digging in, I think this simple approach works well. It passes all tests on master, doesn't interfere with pagination (like previous attempt 1) and doesn't add any additional configuration or parameters (like previous attempt 2). Please consider a merge.