olivere / elastic

Deprecated: Use the official Elasticsearch client for Go at https://github.com/elastic/go-elasticsearch
https://olivere.github.io/elastic/
MIT License
7.39k stars 1.15k forks source link

SetTraceLog comes out mistaken code in v5 version #1642

Closed askme-gpt closed 2 years ago

askme-gpt commented 2 years ago

Which version of Elastic are you using?

[ ] elastic.v7 (for Elasticsearch 7.x) [ ] elastic.v6 (for Elasticsearch 6.x) [√ ] elastic.v5 (for Elasticsearch 5.x) [ ] elastic.v3 (for Elasticsearch 2.x) [ ] elastic.v2 (for Elasticsearch 1.x)

Please describe the expected behavior

I put elastic5.SetTraceLog(log.New(os.Stdout, "Tracer ", log.LstdFlags)) option into ClientOptionFunc. and I get the result and show the trace log ,but it mistaken code comes out.

Please describe the actual behavior

image

Any steps to reproduce the behavior?

indexs := []string{
        "xxx-eventlog-2021",
        "xxx-eventlog-2022",
    }

    svc := elastic5.NewScrollService(client.Instance()).
        Index(indexs...). 
        Query(boolQuery). 
        Size(1)

    pages := 0
    numDocs := 0

    for {
        res, err := svc.Do(context.Background())
        if err == io.EOF {
            break
        }
        if err != nil {
            fmt.Println(err)
        }
        if res == nil {
            fmt.Println("expected results != nil; got nil")
        }
        if res.Hits == nil {
            fmt.Println("expected results.Hits != nil; got nil")
        }

        pages++

        for _, hit := range res.Hits.Hits {
            item := make(map[string]interface{})
            err := json.Unmarshal(*hit.Source, &item)
            if err != nil {
                fmt.Println(err)
            }
            numDocs++
        }
    }
askme-gpt commented 2 years ago

the results format is right . image

askme-gpt commented 2 years ago

I set the gzip option ,sorry.