0

I am trying to move from Elastic High level rest client to Elastic Java API Client (Low Level Rest Client). I am able to get the response, but i want to set the timeout for my elastic query.

But this timeout method is accepting a string value, which i am not able to pass the value here.

String searchText = "bike";

SearchResponse<Product> response = esClient.search(s -> s
    .index("products") 
 .timeout()
    .query(q -> q      
        .match(t -> t   
            .field("name")  
            .query(searchText)
        )
    ),
    Product.class      
);

This is the documentation for the method https://artifacts.elastic.co/javadoc/co/elastic/clients/elasticsearch-java/8.0.1/co/elastic/clients/elasticsearch/core/SearchRequest.Builder.html#timeout(java.lang.String)

Can someone help, how can I pass timeout value as String ??

Ashish Mishra
  • 145
  • 3
  • 13
  • from the docs, it says to use RestClientBuilder https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/master/_timeouts.html. There's another post similar to this. https://stackoverflow.com/questions/65503584/change-timeout-in-run-time-elasticsearch-resthighlevelclient – Clark Ngo Sep 19 '22 at 21:51
  • RestClientBuilder will help to set connect and socket timeout, I am trying to set a timeout for individual queries. Also, the link you shared was for High LevelRest client, whereas I am trying to use Low-Level Rest CLient, as the high level is getting deprecated – Ashish Mishra Sep 20 '22 at 01:42

1 Answers1

1

I was able to solve this by passing a simple time value,

String searchText = "bike";

SearchResponse<Product> response = esClient.search(s -> s
    .index("products") 
 .timeout("450ms")
    .query(q -> q      
        .match(t -> t   
            .field("name")  
            .query(searchText)
        )
    ),
    Product.class      
);

Ashish Mishra
  • 145
  • 3
  • 13