Stop search if client has disconnected

Is it possible to stop the search if the main HTTP connection is closed by the client?

My use case: "a web-site with Nginx+php+elasticsearch, public user does a search and closes the page immediately"

I think it's possible with task API, but I am wondering if there is a more elegant way.

Do you mean that you have very long queries running? Task API might help indeed but only for long queries (which you should try to avoid anyway).

It's not about long queries, we have timeout for that, it's about "zombie" search, when the end-user has left the web site, but elasticsearch is still searching.

I must setup a monitoring to count how many ES queries are "abandoned" by Php, maybe it's very little, but I am curious to know if it's possible to optimize our ES cluster by stoping "zombie" searches.

Do you mean that it is still consuming resources on elasticsearch end?
That should not happen AFAIK.

I think the Task API's X-Opaque-Id header support is the most suitable mechanism for this purpose; if a value is supplied in the search call, it can be used to cancel the tasks with that value after client has aborted.

1 Like

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