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

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?

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

Yes, we are using.

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.

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