fix: 0 size

This commit is contained in:
loveuer
2024-08-05 11:07:08 +08:00
parent ebb4365135
commit 2c80079a8f
4 changed files with 28 additions and 6 deletions

View File

@ -199,11 +199,14 @@ func ReadDataV2(
close(errCh)
}()
fina_size := util.AbsMin(size, max-total)
log.Debug("es7.read: size = %d, max = %d, total = %d, fina size = %d", size, max, total, fina_size)
for {
qs = []func(*esapi.SearchRequest){
client.Search.WithContext(util.TimeoutCtx(ctx, 30)),
client.Search.WithIndex(index),
client.Search.WithSize(int(util.Min(size, max-total))),
client.Search.WithSize(int(fina_size)),
client.Search.WithSort(sorts...),
}
@ -221,6 +224,8 @@ func ReadDataV2(
return
}
log.Debug("body raw: %s", string(bs))
qs = append(qs, client.Search.WithBody(bytes.NewReader(bs)))
if resp, err = client.Search(qs...); err != nil {
errCh <- err
@ -247,6 +252,8 @@ func ReadDataV2(
dataCh <- result.Hits.Hits
total += uint64(len(result.Hits.Hits))
log.Debug("es7.read: total: %d", total)
if uint64(len(result.Hits.Hits)) < size || (max > 0 && total >= max) {
break
}