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

panic: json: cannot unmarshal number into Go struct field SearchHits.hits.total of type elastic.TotalHits #1208

Closed zhongshuiping closed 4 years ago

zhongshuiping commented 4 years ago

Please use the following questions as a guideline to help me answer your issue/question without further inquiry. Thank you.

Which version of Elastic are you using?

[ 1] elastic.v6 (for Elasticsearch 6.x)

Please describe the expected behavior

    query := elastic.NewTermQuery("content", "hillo")

result, err := client.Search().
    Index("wenshu").
    Query(query).
    Sort("type",true).
    Pretty(true).
    Do(context.Background())

Please describe the actual behavior

Why do I always report errors when I run?

Any steps to reproduce the behavior?

olivere commented 4 years ago

The error indicates that you're using a combination of Elasticsearch 6 and elastic v7 or vice versa. The reason for this error is that ES 7.x changed the response structure to return the total hits.

See e.g. https://github.com/olivere/elastic/issues/1007 for a detailed discussion.