elasticsearch 为什么searchResult.TotalHits()与len(searchResult.Hits.Hits)不同?,elasticsearch,go,elasticsearch,Go" /> elasticsearch 为什么searchResult.TotalHits()与len(searchResult.Hits.Hits)不同?,elasticsearch,go,elasticsearch,Go" />

elasticsearch 为什么searchResult.TotalHits()与len(searchResult.Hits.Hits)不同?

elasticsearch 为什么searchResult.TotalHits()与len(searchResult.Hits.Hits)不同?,elasticsearch,go,elasticsearch,Go,我使用golang elastic 5 API在ElasticSearch中运行查询。我用searchResult.TotalHits()检查点击数,它给了我一个很大的数字(超过100),但当我尝试迭代点击数时,它只给出10个实体。另外,当我检查len(searchResult.Hits.Hits)变量时,我得到10 当我选择少于10个实体时,我尝试了不同的查询,效果很好 query = elastic.NewBoolQuery() ctx := context.Background() qu

我使用golang elastic 5 API在ElasticSearch中运行查询。我用searchResult.TotalHits()检查点击数,它给了我一个很大的数字(超过100),但当我尝试迭代点击数时,它只给出10个实体。另外,当我检查len(searchResult.Hits.Hits)变量时,我得到10

当我选择少于10个实体时,我尝试了不同的查询,效果很好

query = elastic.NewBoolQuery()
ctx := context.Background()

query = query.Must(elastic.NewTermQuery("key0", "term"),
    elastic.NewWildcardQuery("key1", "*term2*"),
    elastic.NewWildcardQuery("key3", "*.*"),
    elastic.NewRangeQuery("timestamp").From(fromTime).To(toTime),
)
searchResult, err = client.Search().Index("index").
    Query(query).Pretty(true).Do(ctx)
fmt.Printf("TotalHits(): %v", searchResult.TotalHits()) //It gives me 482
fmt.Printf("length of the hits array: %v", len(searchResult.Hits.Hits)) //It gives 10
for _, hit := range searchResult.Hits.Hits {
    var tweet Tweet
    _ = json.Unmarshal(*hit.Source, &tweet)
            fmt.Printf("entity: %s", tweet) //It prints 10 entity
}

我做错了什么?搜索结果中是否有批次,或者解决方案可能是什么?

您的问题中没有指定批次,因此如果您使用的是其他客户端库(如官方客户端),请发表评论,但您似乎使用的是github.com/olivere/elastic。基于该假设,您看到的是默认结果集大小10。
TotalHits
数字是与您的查询匹配的文档总数;
点击次数
是当前结果中返回的次数,您可以使用中的
排序
对其进行操作<代码>大小
记录如下:

Size是要返回的搜索命中数。默认值为10


您正在使用哪个弹性客户端库?