uptasticsearch
uptasticsearch copied to clipboard
More specific error messages in R package
Discovered while working on #155. When the R client receives an error from ES (a non-2xx response code), currently the code fails with an error just like "error: 404"
or something like that.
I think it would be valuable to instead have uptasticsearch
trap non-2xx response codes and then log out the full content of the error message from Elasticsearch.
For example, before fixing #155 I found that running this code
uptasticsearch::es_search(
es_host = "http://127.0.0.1:9200"
, es_index = "shakespeare"
, max_hits = 100
, query = "{\"aggs\": {\"name_i_picked\": {\"terms\": {\"field\": \"speaker\", \"size\": 12}}}}"
)
returns
INFO [2019-08-21 22:35:37] es_search detected that this is an aggs request and will only return aggregation results.
Request failed [400]. Retrying in 1 seconds...
Request failed [400]. Retrying in 1 seconds...
Error in .search_request(es_host = es_host, es_index = es_index, trailing_args = "size=0", :
Bad Request (HTTP 400).
Where the same curl request
curl -X POST \
-i \
"http://127.0.0.1:9200/shakespeare/_search" \
-H "Content-Type: application/json" \
-d '{"aggs": {"name_i_picked": {"terms": {"field": "speaker", "size": 12}}}}'
returns the much more informative error
HTTP/1.1 400 Bad Request
content-type: application/json; charset=UTF-8
content-length: 1442
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [speaker] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"shakespeare","node":"FXsoOzioR_CZqUSQMsWmAg","reason":{"type":"illegal_argument_exception","reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [speaker] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."}}],"caused_by":{"type":"illegal_argument_exception","reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [speaker] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.","caused_by":{"type":"illegal_argument_exception","reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [speaker] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."}}},"status":400}