# Getting 504 Gateway Timeout while fetching data If I am using High-level client?

**URL:** <https://discuss.elastic.co/t/getting-504-gateway-timeout-while-fetching-data-if-i-am-using-high-level-client/179592>\
**Category:** Elasticsearch\
**Created:** [May 3, 2019, 9:45pm UTC](https://discuss.elastic.co/t/getting-504-gateway-timeout-while-fetching-data-if-i-am-using-high-level-client/179592 "2019-05-03T21:45:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aashrithVarikuti](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aashrithvarikuti/32/42539_2.png) [@aashrithVarikuti](https://discuss.elastic.co/u/aashrithVarikuti)\
**Post date:** [May 3, 2019, 9:45pm UTC](https://discuss.elastic.co/t/getting-504-gateway-timeout-while-fetching-data-if-i-am-using-high-level-client/179592/1 "2019-05-03T21:45:32Z")

</div>

I am using elastic search high-level client version 6.3.1in my project.

My goal is single request needs to get data from multiple indexes.

I implemented query using NestedQueryBuilder. But I am seeing lot of performance issues like:

1. While fetching the data it's taking to much time and getting 504 If we have more results.
2. Sometimes even less data also it's taking time to fetch the results.
3. If I am hitting 100 requests each request it's increasing the loadtime.

**Here is the query I am constructing:**

// public static response searchItem(String searchField, String index) {  
MatchQueryBuilder matchQueryProduct = QueryBuilders.matchQuery(PLAN, plan);  
NestedQueryBuilder nestedFieldQuery = QueryBuilders.nestedQuery(products,  
QueryBuilders.boolQuery().must(QueryBuilders.matchQuery(SEARCHFIELD, searchField)),  
ScoreMode.Max);  
BoolQueryBuilder boolMustQuery = QueryBuilders.boolQuery()  
.must(matchQueryProduct)  
.must(nestedFieldQuery);  
if (accessories != null && !accessories.isEmpty()) {  
MatchQueryBuilder matchQueryAccessories = QueryBuilders.matchQuery(ACCESSORIES, accessories);  
boolMustQuery.must(matchQueryAccessories);  
}  
SearchRequest searchRequest = createSearchRequest(index).source(SearchSourceBuilder.searchSource()  
.size(450)  
.fetchSource(new String{}, new String{})  
.query(boolMustQuery));  
return ProductSearch.query(searchRequest);  
} //

ProductSearch.java

// public static SearchResponse elasticSearchQuery(SearchRequest queryRequest) {  
RestHighLevelClient restHighLevelClient = createHighLevelClient(env));  
SearchResponse searchResponse = restHighLevelClient.search(queryRequest);  
return searchResponse;  
}  
} //

And below is query it's generating:

// POST index\_name/\_search  
{  
"query": {  
"bool": {  
"must": [  
{  
"bool": {  
"must": [  
{  
"match": {  
"plan": {  
"query": "2years",  
"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  
}  
}  
},  
{  
"match": {  
"accessories": {  
"query": "screen gaurd",  
"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  
}  
}  
}  
],  
"adjust\_pure\_negative": true,  
"boost": 1  
}  
},  
{  
"nested": {  
"query": {  
"bool": {  
"must": [  
{  
"match": {  
"products.product": {  
"query": "SAMSUNG.S8",  
"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  
}  
}  
}  
],  
"adjust\_pure\_negative": true,  
"boost": 1  
}  
},  
"path": "products",  
"ignore\_unmapped": false,  
"score\_mode": "none",  
"boost": 1  
}  
}  
],  
"adjust\_pure\_negative": true,  
"boost": 1  
}  
},  
"\_source": {  
"includes": ,  
"excludes":   
}  
}

And in generated query I am seeing unnecessary parameters How to exclude those parameters?

How to increase query performance? Is there any alternate way to generate query with good performance?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [May 6, 2019, 8:19am UTC](https://discuss.elastic.co/t/getting-504-gateway-timeout-while-fetching-data-if-i-am-using-high-level-client/179592/2 "2019-05-06T08:19:35Z")

</div>

Are you using any type of forwarder/load-balancer/proxy between your client and elasticsearch?

---

<div class="post-metadata">

**Author:** ![aashrithVarikuti](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aashrithvarikuti/32/42539_2.png) [@aashrithVarikuti](https://discuss.elastic.co/u/aashrithVarikuti)\
**Post date:** [May 6, 2019, 7:01pm UTC](https://discuss.elastic.co/t/getting-504-gateway-timeout-while-fetching-data-if-i-am-using-high-level-client/179592/3 "2019-05-06T19:01:38Z")

</div>

Yes, we are using.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [May 7, 2019, 9:33am UTC](https://discuss.elastic.co/t/getting-504-gateway-timeout-while-fetching-data-if-i-am-using-high-level-client/179592/4 "2019-05-07T09:33:01Z")

</div>

ok, it seems that the proxy is generating that error message. Which means you need to take a look at your elasticsearch log files, if there is any indication why there is no response. Also check, what the timeout settings for that proxy are, maybe you can increase them. If possible, test the exact same query without the proxy and see, if the problem is the same.

---

<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:** [June 4, 2019, 9:33am UTC](https://discuss.elastic.co/t/getting-504-gateway-timeout-while-fetching-data-if-i-am-using-high-level-client/179592/5 "2019-06-04T09:33:10Z")

</div>

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