opensearch-java icon indicating copy to clipboard operation
opensearch-java copied to clipboard

[FEATURE] Add cancel_after_time_interval to SearchRequest and MsearchRequest

Open dhauverNS opened this issue 1 year ago • 1 comments

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.

dhauverNS avatar Jul 30 '24 15:07 dhauverNS

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

dblock avatar Jul 30 '24 17:07 dblock

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).

Xtansia avatar Aug 02 '24 04:08 Xtansia

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

chanon-onman avatar Aug 21 '24 23:08 chanon-onman

@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 avatar Aug 21 '24 23:08 Xtansia

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

Xtansia avatar Aug 27 '24 21:08 Xtansia