opensearch-project / opensearch-java

Java Client for OpenSearch
Apache License 2.0
124 stars 183 forks source link

[FEATURE] Add cancel_after_time_interval to SearchRequest and MsearchRequest #1116

Closed dhauverNS closed 2 months ago

dhauverNS commented 3 months ago

Is your feature request related to a problem?

The cancel_after_time_interval parameter does not exist for search and msearch requests in the Java client.

What solution would you like?

Add cancel_after_time_interval to SearchRequest and MsearchRequest in the Java client.

What alternatives have you considered?

I have not found a workaround.

Do you have any additional context?

Being able to use this parameter is especially useful when using an AWS hosted OpenSearch cluster. Because AWS does not provide a way to set the default cancel_after_time_interval setting for a cluster, there doesn't seem to be any other way to ensure that a request which can't be handled in a reasonable time will be cancelled. We have occasionally encountered outages caused by extremely complicated, long-running search requests bogging down the cluster.

This parameter was missing from the OpenSearch Open API spec for years, and was finally added in June 2024: https://github.com/opensearch-project/opensearch-api-specification/issues/273

I see there is work underway to generate the Java client code from the Open API specification, which hopefully will eventually provide a solution. But it would be very useful to be able to set this parameter in the interim. https://github.com/opensearch-project/opensearch-java/pull/366 is the recently merged PR to which I am referring.

dblock commented 3 months ago

@Xtansia what are the changes needed in the generator to pick that up? Maybe @dhauverNS can help?

Xtansia commented 3 months ago

The size and complexity of the SearchRequest & query types means it's non-trivial to do the initial generation of them. If you wanted to really dig into it that'd be amazing, but I wouldn't categorise it as a "good first issue" per se. So in the meantime it is significantly easier to just add the parameter to the two request classes by hand (copying something like the scroll parameter).

chanon-onman commented 2 months ago

I got the same issue, will this be released in the next version?

Xtansia commented 2 months ago

@chanon-onman A fix was just merged (thanks to @urinud) so should currently be available in 2.14.0-SNAPSHOT, I'll look to do a proper release of 2.14.0 early next week

Xtansia commented 2 months ago

v2.14.0 has been released and includes the fix for this issue