Example using PIT for opensearch-java

Versions (relevant - OpenSearch/Dashboard/Server OS/Browser):
OpenSearch 2.11.1

Describe the issue:
Trying to get pagination working for opensearch. Had it working with Elasticsearch but, have moved over to opensearch which apparently implemented this feature in a different way. I am creating a SearchRequest.Builder object after having successfully created a pitId using CreatePitRequest but, getting error when attempting a search with a request as defined below.

		final Query query = QueryBuilders.match().field(query_field).query(FieldValue.of(query_field_val)).build().toQuery();

 SearchRequest.Builder searchRequest = new SearchRequest.Builder()
						.pit(new Pit.Builder().id(pitId).keepAlive(keepAlive.toString()).build()) 
						.size(size)// MAX_QUERY_RESULTS)
						.query(query).sort(sort -> sort.field(field -> field.field(sort_field)));

Would appreciate if someone could assist with an example as I wasn’t able to find any utilizing PIT with opensearch for java.

Configuration:

<dependency>
			<groupId>org.opensearch.client</groupId>
			<artifactId>spring-data-opensearch-starter</artifactId>
			<version>1.6.0</version>
		</dependency>
		<dependency>
  <groupId>org.opensearch.client</groupId>
  <artifactId>opensearch-java</artifactId>
  <version>2.11.1</version>
</dependency>

Relevant Logs or Screenshots:

org.opensearch.client.opensearch._types.OpenSearchException: Request failed: [x_content_parse_exception] [1:1554] [pit] failed to parse field [keep_alive]

@sunshine16 curious what is the value of keepAlive ? It is supposed to be Time, fe 5s. Thank you

@reta Below is the definition I have for keep alive

final Time keepAlive = new Time.Builder().time(“3m”).build();

function definition is expecting a string as seen below which is why I toString() the Time object.

Builder org.opensearch.client.opensearch.core.search.Pit.Builder.keepAlive(@Nullable String keepAlive)

@reta I actually see my issue. I needed to call .time() on the keepAlive object vs toString. Thanks, for bringing that to my attention.