Skip to content

Commit 789e4a9

Browse files
committed
fix: opensearch index api
1 parent d23ad4f commit 789e4a9

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/clients/common/document.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@ def search_documents(self, index: str, body: Dict) -> Dict:
99

1010
def index_document(self, index: str, document: Dict, id: Optional[str] = None) -> Dict:
1111
"""Creates a new document in the index."""
12-
if id is not None:
13-
return self.client.index(index=index, document=document, id=id)
12+
# Handle parameter name differences between Elasticsearch and OpenSearch
13+
if self.engine_type == "elasticsearch":
14+
# For Elasticsearch: index(index, document, id=None, ...)
15+
if id is not None:
16+
return self.client.index(index=index, document=document, id=id)
17+
else:
18+
return self.client.index(index=index, document=document)
1419
else:
15-
return self.client.index(index=index, document=document)
20+
# For OpenSearch: index(index, body, id=None, ...)
21+
if id is not None:
22+
return self.client.index(index=index, body=document, id=id)
23+
else:
24+
return self.client.index(index=index, body=document)
1625

1726
def get_document(self, index: str, id: str) -> Dict:
1827
"""Get a document by ID."""

0 commit comments

Comments
 (0)