Elasticsearch _count查询请求缓存 [英] Elasticsearch _count query request cache
只要文档没有说明,请转到源代码;-)
在这种情况下,如果我们查看 此外,当 因此,从这一点上,我们可以推断出实际上也对计数查询进行了缓存. Taken from docs: https://www.elastic.co/guide/en/elasticsearch/reference/7.9/shard-request-cache.html#shard-request-cache By default, the requests cache will only cache the results of search requests where Most queries that use now (see Date Math) cannot be cached. Scripted queries that use the API calls which are non-deterministic, such as However how does this play with _count queries? _count queries behave almost exactly the same as _search queries with I'd expect request cache to cache count queries as well, but couldn't find any information about it. Whenever the documentation doesn't tell, go to the source ;-) In this case, if we look at the source of Furthermore, when building the response we can see that the So, from that, we can deduce that count queries are de facto cached as well. 这篇关于Elasticsearch _count查询请求缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
size=0
, so it will not cache hits, but it will cache hits.total
, aggregations
, and suggestions
.Math.random()
or new Date()
are not cached.size=0
?RestCountAction
(i.e. the class handling the _count
endpoint), we can see that what it actually does is creating a SearchRequest
with size: 0
a search request
|
v
SearchRequest countRequest = new SearchRequest(Strings.splitStringByCommaToArray(request.param("index")));
countRequest.indicesOptions(IndicesOptions.fromRequest(request, countRequest.indicesOptions()));
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(0).trackTotalHits(true);
^
|
with size 0
count
value is actually the value of hits.total
from the SearchResponse
: builder.field("count", response.getHits().getTotalHits().value);