Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

different 404 search results using SDK and HTTP request #4934

Open
tuziben opened this issue May 4, 2024 · 4 comments
Open

different 404 search results using SDK and HTTP request #4934

tuziben opened this issue May 4, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@tuziben
Copy link
Contributor

tuziben commented May 4, 2024

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 tuziben added the bug Something isn't working label May 4, 2024
@guilload guilload self-assigned this May 6, 2024
@guilload
Copy link
Member

guilload commented May 6, 2024

Do you observe this behavior before or after #4900?

@tuziben
Copy link
Contributor Author

tuziben commented May 6, 2024

It's still reproducible with this commit #4930.

@guilload
Copy link
Member

guilload commented May 6, 2024

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.

@tuziben
Copy link
Contributor Author

tuziben commented May 8, 2024

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": {}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants