opensearch-project / opensearch-py

Python Client for OpenSearch
https://opensearch.org/docs/latest/clients/python/
Apache License 2.0
328 stars 167 forks source link

[BUG] .refresh() returns 404 on existing index (on Serverless) #646

Closed shacker closed 3 weeks ago

shacker commented 7 months ago

What is the bug?

If I call .exists() to confirm that a given index exists:

>>> client.indices.exists("locations-1234")
True

Then it doesn't make sense that calling .refresh() on the same index should return 404:

>>> client.indices.refresh("locations-1234")
[stack trace skipped]
opensearchpy.exceptions.NotFoundError: NotFoundError(404, '')

It may be failing for some other reason, but it shouldn't be 404 since we know it exists.

Note this happens only in an AWS Serverless OpenSearch environment. The bug does not occur on localhost with brew-installed OpenSearch.

I see .refresh() that is documented as unsupported, but the library should be able to detect the environment and return a better response.

How can one reproduce the bug?

As above

What is the expected behavior?

A useful error message and different return value is returned.

What is your host/environment?

AWS Serverless

Do you have any screenshots?

CleanShot 2024-01-16 at 14 59 03@2x

Do you have any additional context?

N/A

saimedhi commented 7 months ago

Hello @shacker, I will take a look. And also If you're interested in contributing, feel free to take it up. Thank you :)

dblock commented 7 months ago

I believe this is just not supported by serverless.

https://repost.aws/questions/QUSYfaKYMzTn2dUPr-oW9maA/aws-opensearch-serverless-supports-for-refresh-wait-for-and-refresh-true

shacker commented 7 months ago

@dblock Correct - I mentioned that in my bug report. I'm saying that 404 is an incorrect response for an unsupported feature, that's all. Cheers.

dblock commented 7 months ago

Hm, what do you think it should raise? I think the service deliberately chose 404s for things that don't exist.

shacker commented 7 months ago

@dblock 404 is for a resource (record or file) that doesn't exist, like a non-existent index name. I think calling a method that's unsupported should be 405, "Method not allowed."

dblock commented 3 weeks ago

I decided to close this, no hard feelings. This isn't a problem with the client which just returns what the server returns.

I don't disagree that 405 may be a better code btw, but I doubt that Amazon Serverless would change the 404 to a 405.