olivere / elastic

Deprecated: Use the official Elasticsearch client for Go at https://github.com/elastic/go-elasticsearch

Home Page:https://olivere.github.io/elastic/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get detailed error info when use SearchService.Do ?

NBJ2017 opened this issue · comments

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.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

In most time, the SearchService.Do only return the error code and brief error info, like " 400 (Bad Request): all shards failed [type=search_phase_execution_exception]", It's hard to know the error detail.

The reason is that source code hide elastic search server ret detail. (https://github.com/olivere/elastic/blob/release-branch.v7/search.go L627-L657)

So, I hope to return more details, like

"root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "Result window is too large, from + size must be less than or equal to: [65536] but was [10000000]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level setting."
      }
    ],

Please describe the actual behavior

Any steps to reproduce the behavior?

The easiest way is set search param "size" as 1000000, then you can see, the SearchService.Do response error is so simple and it's hard to trace error.

You can find out about all those details with helper functions like ErrorReason etc. See errors.go.