es分页用from+size的方式超过1万条就查不出数据了。
查询大于1万的数据这里使用scroll和go-elasiticsearch简单写一个demo
package main
import (
"bytes"
"fmt"
"io"
"log"
"net/http"
"os"
"strconv"
"strings"
"sync"
"time"
"github.com/elastic/go-elasticsearch/v8"
"github.com/tidwall/gjson"
)
var c *elasticsearch.Client
var once sync.Once
func main() {
log.SetFlags(0) //这里设置的0即取消log格式化输出,输出的内容和使用fmt包下的println()格式一样
var (
batchNum int
scrollID string
)
es := setElastic([]string{"http://ip:9200"})
// Index 100 documents into the "test-scroll" index
//测试写入100个document
log.Println("Indexing the documents...")
for i := 1; i <= 100; i++ {
res, err := es.Index(
"test-scroll",
strings.NewReader(`{"title" : "test"}`),
es.Index.WithDocumentID(strconv.Itoa(i)),
)
if err != nil || re
声明:本站所有文章,如无特殊说明或标注,均为网络收集发布。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。