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:
- While fetching the data it's taking to much time and getting 504 If we have more results.
- Sometimes even less data also it's taking time to fetch the results.
- 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?