1

Below is the Rest client initialization.

RestHighLevelClient client = new 
RestHighLevelClient(RestClient.builder(httpHost).setRequestConfigCallback(
    requestConfigBuilder -> requestConfigBuilder
        .setConnectTimeout(30000)
        .setSocketTimeout(90000));

Is there a way to change timeout values on the fly without reinitializing the rest client ?

Ruchira Gayan Ranaweera
  • 34,993
  • 17
  • 75
  • 115

1 Answers1

1

Yes you can very well define the timeout for each query level, please see this timeout method which is available in JHLRC and can be added at query level.

So sample java code for your query looks like

SearchRequest searchRequest = new SearchRequest(USERS_INDEX_NAME);
        BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
        boolQueryBuilder.minimumShouldMatch(1);
        MatchQueryBuilder emailMatchQueryBuilder = new MatchQueryBuilder("emailId", email);
        MatchQueryBuilder userIdMatchQueryBuilder = new MatchQueryBuilder("userId", userId);
        MatchQueryBuilder mobileMatchQueryBuilder = new MatchQueryBuilder("mobileNumber", mobile);
        boolQueryBuilder.should(emailMatchQueryBuilder);
        boolQueryBuilder.should(userIdMatchQueryBuilder);
        boolQueryBuilder.should(mobileMatchQueryBuilder);

        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        searchSourceBuilder.timeout(new TimeValue(1000)); // note this
Amit
  • 30,756
  • 6
  • 57
  • 88
  • 1
    Thanks for your answer. This is for re-indexing. Couldn't see same kind of a implementation is there with JHLRC for Re-indexing. – Ruchira Gayan Ranaweera Jan 04 '21 at 03:32
  • @RuchiraGayanRanaweera, through my answer I tried to explain that its a generic method which can be added at any query level, did you try adding it at your re-indexing code?? – Amit Jan 04 '21 at 03:42
  • 1
    Yes. Below code is not working. Timeout defined below is not reflecting,. Always taking the timeout defined in client level. `ReindexRequest request = new ReindexRequest(); request.setSourceIndices(indexName); request.setDestIndex(destinationIndex); request.setTimeout(new TimeValue(30000L));` `ReindexRequestBuilder` doesn't have timeout option to set. – Ruchira Gayan Ranaweera Jan 04 '21 at 04:17
  • 1
    @RuchiraGayanRanaweera this is strange, how did you verify its not working and instead taking the timeout defined at client level?? i would suggest open a issue at https://github.com/elastic/elasticsearch/issues – Amit Jan 04 '21 at 04:38
  • 1
    I put 30s timeout to `RestHighLevelClient` and 30s timeout in `ReindexRequest`. When it throws the timeout exception I increased the timeout to 60s in `ReindexRequest` on the fly. Still it gives the timeout after 30s. Then I realized, it is taking the timeout from client but not from the re-indexing request. – Ruchira Gayan Ranaweera Jan 04 '21 at 04:43
  • 1
    Reported a bug https://github.com/elastic/elasticsearch/issues/66913 – Ruchira Gayan Ranaweera Jan 04 '21 at 05:40