Open a point in timeedit

A point in time must be opened before being used in search requests. An OpenPointInTimeRequest requires an index and keepAlive arguments:

OpenPointInTimeRequest openRequest = new OpenPointInTimeRequest("posts"); 
openRequest.keepAlive(TimeValue.timeValueMinutes(30)); 
OpenPointInTimeResponse openResponse = client.openPointInTime(openRequest, RequestOptions.DEFAULT);
String pitId = openResponse.getPointInTimeId(); 

Create an OpenPointInTimeRequest with the target indices

Set the keep_alive - a required parameter, which tells Elasticsearch how long it should keep a point in time around.

Read the returned point in time id, which points to the search context that’s being kept alive and will be used in the search requests.

Optional argumentsedit

The following arguments can optionally be provided:

openRequest.indicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN_CLOSED); 

Setting IndicesOptions controls how unavailable indices are resolved and how wildcard expressions are expanded

openRequest.routing("routing"); 

Set a routing parameter

openRequest.preference("_local"); 

Use the preference parameter e.g. to execute the search to prefer local shards. The default is to randomize across shards.