quickwit icon indicating copy to clipboard operation
quickwit copied to clipboard

different 404 search results using SDK and HTTP request

Open tuziben opened this issue 9 months ago • 4 comments

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)

tuziben avatar May 04 '24 09:05 tuziben