# The first request on my java application the search is slow but took is small and then it become quick

**URL:** <https://discuss.elastic.co/t/the-first-request-on-my-java-application-the-search-is-slow-but-took-is-small-and-then-it-become-quick/319715>\
**Category:** Elasticsearch\
**Tags:** docker\
**Created:** [November 24, 2022, 8:21am UTC](https://discuss.elastic.co/t/the-first-request-on-my-java-application-the-search-is-slow-but-took-is-small-and-then-it-become-quick/319715 "2022-11-24T08:21:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MonkAscetic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/monkascetic/32/113718_2.png) [@MonkAscetic](https://discuss.elastic.co/u/MonkAscetic)\
**Post date:** [November 24, 2022, 8:21am UTC](https://discuss.elastic.co/t/the-first-request-on-my-java-application-the-search-is-slow-but-took-is-small-and-then-it-become-quick/319715/1 "2022-11-24T08:21:53Z")

</div>

the first request on my java application the search is slow but took is small and then it become quick, reponse took between 10ms and 20ms but actually is 2s,I used elasticseach 7.17.2,and client is ElasticsearchClient

```auto
 RestClient restClient = RestClient.builder(httpHosts.toArray(new HttpHost[httpHosts.size()])).
                setHttpClientConfigCallback(httpClientBuilder ->
                        httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)).build();
        ObjectMapper mapper = new ObjectMapper();
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.registerModule(new JavaTimeModule());
        mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
        JacksonJsonpMapper jacksonJsonpMapper = new JacksonJsonpMapper(mapper);

        ElasticsearchTransport transport = new RestClientTransport(
                restClient, jacksonJsonpMapper);
        ElasticsearchClient client = new ElasticsearchClient(transport);

```

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [November 30, 2022, 1:14am UTC](https://discuss.elastic.co/t/the-first-request-on-my-java-application-the-search-is-slow-but-took-is-small-and-then-it-become-quick/319715/2 "2022-11-30T01:14:37Z")

</div>

Welcome to our community! 😃

That's not unexpected, as Elasticsearch will cache the results for future queries.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 28, 2022, 1:15am UTC](https://discuss.elastic.co/t/the-first-request-on-my-java-application-the-search-is-slow-but-took-is-small-and-then-it-become-quick/319715/3 "2022-12-28T01:15:29Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
