接手老代码,发现有一个接口查询一直超时,调查发现是es聚合value_count查询超时(3分钟以上),同时log输入es警告信息。
[ignore_throttled] parameter is deprecated because frozen indices have been deprecated. Consider cold or frozen tiers in place of frozen indices."]
注:es版本7.17.5文章来源:https://www.toymoban.com/news/detail-503783.html
调查之后考虑是es客户端版本低,支持不好,将ElasticsearchRestTemplate更换为RestHighLevelClient,并重写查询语句,查询时间优化到100+ms。文章来源地址https://www.toymoban.com/news/detail-503783.html
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
ValueCountAggregationBuilder aggregation = AggregationBuilders.count("name")
.field("key.keyword");
searchSourceBuilder.aggregation(aggregation);
searchSourceBuilder.query(boolQuery);
SearchRequest searchRequest = new SearchRequest();
searchRequest.indices("es_table");
searchRequest.source(searchSourceBuilder);
SearchResponse search = restHighLevelClient.search(searchRequest,
RequestOptions.DEFAULT);
ValueCount userId = search.getAggregations().get("name");
value = Math.toIntExact(userId.getValue());
到了这里,关于ElasticsearchRestTemplate导致的查询超时的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!