Search query is very slow while using spring-data-elasticsearch

I've an index which have:

  • 6 shards
  • 6 replica shards
  • more than 1crore doc (row) in that single index
  • 27 fields
  • fields types are text, long and date
  • index.max_return_result = 50000

Now I run the following query from postman:

curl --location --request POST 'http://es_host/my-index/_search' \
--header 'Content-Type: application/json' \
--data-raw '{
    "from": 0,
    "size": 10000,
    "query": {
        "bool": {
            "must": [
                    "match": {
                        "name": {
                            "query": "huda",
                            "operator": "OR",
                            "prefix_length": 0,
                            "max_expansions": 50,
                            "fuzzy_transpositions": true,
                            "lenient": false,
                            "zero_terms_query": "NONE",
                            "auto_generate_synonyms_phrase_query": true,
                            "boost": 1.0
            "adjust_pure_negative": true,
            "boost": 1.0

The above query returns the result in less than 3 secs.

Now if I run the above query from e spring boot service using spring-data-Elasticsearch then it returns the result in 10+ secs.
Here is the code:

BoolQueryBuilder boolQueryBuilder = boolQueryBuilder.must(QueryBuilders.matchQuery(std.getSearchField().getFieldName(), std.getSearchValue1()));

Query searchQuery = new NativeSearchQueryBuilder()
						new FetchSourceFilter(new String[] {fields name.....}, new String[] {}))

		SearchRequest searchRequest = new SearchRequest();
		SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
		try {
			long start = System.currentTimeMillis();"starting with  query in: " + start);
			SearchResponse search =, RequestOptions.DEFAULT);
			long end = System.currentTimeMillis();"query returned with in " + ((end - start) / 1000f));

		} catch (Exception e) {

I'm using:

  • spring boot version 2.7.5
  • my elasticsearch version is 7.17.7 (3 nodes are running)
  • Update or insert in the index will happen very rarely few times in a year so the index a read heavy index.

So why the same query is the same query taking more time in spring boot?
And how can I improve the search performance using spring boot?

The first raw query(without spring boot) is taking more than 2 secs, is it too much also?