我使用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
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?SearchResult中是否有批次或可能是什么解决方案?
| 归档时间: |
|
| 查看次数: |
257 次 |
| 最近记录: |