是否有 API 会 return 基于您的查询搜索有多少结果?

Is there an API that will return how many results there are based your query search?

是否有 api returns 有多少 results/logs 基于您的查询搜索?或者像 NEST 的内置功能,它会告诉你有多少结果,比如 count?因为我有一个 NEST 查询搜索,它将执行以下操作:

var response = await _elasticClient.SearchAsync<EsSource>(s => s
                  .Size(3000) // must see about this
                  .Source(src => src.Includes(i => i
                                    .Fields(f => f.timestamp,
                                            fields => fields.messageTemplate,
                                            fields => fields.message)))
                  .Index("customer-simulation-es-app-logs*")
                  .Query(q => +q
                      .DateRange(dr => dr
                          .Field("@timestamp")
                              .GreaterThanOrEquals("2021-06-07T17:13:54.414-05:00")
                              .LessThanOrEquals(DateTime.Now))));

但我意识到搜索 api 不能超过 10,000 个结果,因为当您对超过 10,000 个结果进行分页时,数组为空。 search api

所以,如果有一个 api 或一个功能可以让您知道根据您的索引有多少结果,或者如果您像我一样进行每月查询搜索以上;知道这个数字后,我可以创建一个 forloop 来对这些文档中的每一个进行分页,比如我可以查看前 10,0000 个匹配项,然后是下一个 10,000 个匹配项的下一次迭代,依此类推。希望这是有道理的,如果需要我会澄清。

Is there an API that will return how many results there are based your query search?

我不知道有任何 ES API 会 return exact 计数。在高值时,它变得非常近似。

array is empty when you paginate beyond 10,000 results.

首先,return超过 10k 的搜索结果非常不寻常。听起来您正在尝试将 ElasticSearch 用作数据库,您可以为 一些 事情做这件事,但不要依赖 ACID 或类似的东西。

要在 ElasticSearch 中对大型结果集进行分页,请创建 point in time and pass that to the search API with the search_after parameter