different 404 search results using SDK and HTTP request
Describe the bug we get different 404 search results using SDK and HTTP requests when searching an not existed index.
QW version: v0.8.1 Go SDK: go-elastic v7.17.1 Python SDK: elasticsearch 8.13.1
The results returned by SDK do not work as expected. That makes us confused.
I tried to read the Rust code but did not find any idea about how to fix it.
HTTP Request
curl -L -X POST 'http://127.0.0.1:7280/api/v1/_elastic/qw-test/_search' -H 'Content-Type: application/json' -d '{
"query": {
"match_all": {}
}
}'
Result
{
"status": 404,
"error": {
"caused_by": null,
"reason": "could not find indexes matching the IDs `[\"qw-test\"]`",
"stack_trace": null,
"type": null
}
}
Go SDK
cfg := elasticsearch.Config{
Addresses: []string{
"http://127.0.0.1:7280/api/v1/_elastic",
},
}
es, err := elasticsearch.NewClient(cfg)
if err != nil {
log.Fatalf("Error creating the client: %s", err)
}
query := `{"query": {"match_all": {}}}`
res, err := es.Search(
es.Search.WithContext(context.Background()),
es.Search.WithIndex("qw-test"),
es.Search.WithBody(strings.NewReader(query)),
es.Search.WithPretty(),
)
if err != nil {
log.Fatalf("Error getting response: %s", err)
}
defer res.Body.Close()
if res.IsError() {
str, _ := json.Marshal(res)
fmt.Println(string(str))
return
}
Result:
{
"StatusCode": 404,
"Header": {
"Access-Control-Allow-Origin": [
"*"
],
"Vary": [
"origin",
"access-control-request-method",
"access-control-request-headers"
],
"Date": [
"Sat, 04 May 2024 09:46:56 GMT"
],
"Content-Type": [
"application/json"
],
"X-Elastic-Product": [
"Elasticsearch"
]
},
"Body": {}
}
Python SDK
from elasticsearch import Elasticsearch
es = Elasticsearch("http://127.0.0.1:7280/api/v1/_elastic")
try:
response = es.search(index="qw-test", body={"query": {"match_all": {}}})
print(response)
except Exception as e:
print(f"An error occurred: {e}")
Result:
An error occurred: NotFoundError(404, None)
Do you observe this behavior before or after #4900?
It's still reproducible with this commit https://github.com/quickwit-oss/quickwit/pull/4930.
Good. I suspect we do not follow the ES API spec for the _search on index not found, which induces the diverging behaviors observed between clients. I'll get to it.
another 400 case
response from CURL
{
"status": 400,
"error": {
"caused_by": null,
"reason": "failed to parse query: `uri:\"/abcd\" AND upstream_addr:*:9015`",
"stack_trace": null,
"type": null
}
}
Response from Go SDK
{
"StatusCode": 400,
"Header": {
"Access-Control-Allow-Origin": [
"*"
],
"Connection": [
"keep-alive"
],
"Content-Type": [
"application/json"
],
"Date": [
"Wed, 08 May 2024 06:14:12 GMT"
],
"Server": [
"nginx/1.22.1"
],
"Vary": [
"origin",
"access-control-request-method",
"access-control-request-headers"
],
"X-Elastic-Product": [
"Elasticsearch"
]
},
"Body": {}
}