opensearch-project / opensearch-py

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

[BUG] client.get calls wrong URL internally if alias present #672

Closed shacker closed 7 months ago

shacker commented 7 months ago

What is the bug?

Given a known index name and document ID, this call should work:

index_name=abc123  # aliased to foo
client.get(index=index_name, id=doc_id)

index_name is aliased to foo, but that shouldn't matter - I'm talking to the index directly and not interested in the alias. I get this error:

GET http://localhost:9200/foo/_doc/7mt5jYsBNvxwk6rSf2uq 

*** opensearchpy.exceptions.RequestError: RequestError(400, 'illegal_argument_exception', "alias [locations-foo] has more than one index associated with it [locations-foo-101-20240125194804.729742, ... ], can't execute a single index op")

Notice that the GET was issued to the alias name, not to the index name, so no wonder I'm getting that error. The GET call should have been issued to

GET http://localhost:9200/abc123/_doc/7mt5jYsBNvxwk6rSf2uq

How can one reproduce the bug?

  1. Create an index, and create an alias to it
  2. Create a document in the index
  3. Call client.get(index=index_name, id=doc_id)

What is the expected behavior?

The call is issued to a URL that includes the index name, not that index's alias

What is your host/environment?

Mac OS 14.1.1 opensearch-py 2.4.2

Do you have any screenshots?

n/a

Do you have any additional context?

n/a

saimedhi commented 7 months ago

Hey @shacker, I followed the steps you mentioned, but everything seems to be working fine. Did I miss anything? Thanks!

index = 'abc1234' client.create(index=index, id=1, body={'title': 'Beauty and the Beast', 'year': 1991}) {'_index': 'abc1234', '_id': '1', '_version': 1, 'result': 'created', '_shards': {'total': 2, 'successful': 1, 'failed': 0}, '_seq_no': 0, '_primary_term': 1}

client.indices.put_alias(index=index, name = 'foo') {'acknowledged': True}

client.get(index=index,id=1) {'_index': 'abc1234', '_id': '1', '_version': 1, '_seq_no': 0, '_primary_term': 1, 'found': True, '_source': {'title': 'Beauty and the Beast', 'year': 1991}}

saimedhi commented 7 months ago

This will also work. Guides can be found here :) index = 'abc12345' client.indices.create(index=index)

client.indices.put_alias(index=index, name = 'foo')

client.create(index=index, id=1, body={'title': 'Beauty and the Beast', 'year': 1991})

client.get(index=index,id=1)

shacker commented 7 months ago

@saimedhi Well, I am embarrassed. I tried to test and document this issue so carefully, but now I cannot reproduce it, and client.get() is working just fine. I don't know what is different between now and this morning, but you're right, it's just fine. My apologies for taking your time. All good!

Also thanks for the link to the guides, very useful.

saimedhi commented 7 months ago

@saimedhi Well, I am embarrassed. I tried to test and document this issue so carefully, but now I cannot reproduce it, and client.get() is working just fine. I don't know what is different between now and this morning, but you're right, it's just fine. My apologies for taking your time. All good!

Also thanks for the link to the guides, very useful.

No worries, happy to hear the guides were useful! Thank you:)

dblock commented 7 months ago

@shacker if you want to help with something, go through the user guides and add some things about aliases if we don't already have it!