Skip to content

Commit baa1260

Browse files
author
s.kazemi
committed
feat: index_exists method for elastic adapter
1 parent a4934ed commit baa1260

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

archipy/adapters/elasticsearch/adapters.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,23 @@ def exists(
258258
"""
259259
return self.client.exists(index=index, id=doc_id, **kwargs)
260260

261+
@override
262+
def index_exists(
263+
self,
264+
index: ElasticsearchIndexType,
265+
**kwargs: object,
266+
) -> ElasticsearchResponseType:
267+
"""Check if an index exists in Elasticsearch.
268+
269+
Args:
270+
index (ElasticsearchIndexType): The index name.
271+
kwargs: Additional keyword arguments passed to the Elasticsearch client.
272+
273+
Returns:
274+
ElasticsearchResponseType: True if the index exists, False otherwise.
275+
"""
276+
return self.client.indices.exists(index=index, **kwargs)
277+
261278

262279
class AsyncElasticsearchAdapter(AsyncElasticsearchPort):
263280
"""Concrete implementation of the AsyncElasticsearchPort interface using elasticsearch-py library.
@@ -495,3 +512,20 @@ async def exists(
495512
ElasticsearchResponseType: True if the document exists, False otherwise.
496513
"""
497514
return await self.client.exists(index=index, id=doc_id, **kwargs)
515+
516+
@override
517+
async def index_exists(
518+
self,
519+
index: ElasticsearchIndexType,
520+
**kwargs: object,
521+
) -> ElasticsearchResponseType:
522+
"""Check if an index exists in Elasticsearch.
523+
524+
Args:
525+
index (ElasticsearchIndexType): The index name.
526+
kwargs: Additional keyword arguments passed to the Elasticsearch client.
527+
528+
Returns:
529+
ElasticsearchResponseType: True if the index exists, False otherwise.
530+
"""
531+
return await self.client.indices.exists(index=index, **kwargs)

archipy/adapters/elasticsearch/ports.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,26 @@ def exists(
228228
"""
229229
raise NotImplementedError
230230

231+
@abstractmethod
232+
def index_exists(
233+
self,
234+
index: ElasticsearchIndexType,
235+
**kwargs: object,
236+
) -> ElasticsearchResponseType:
237+
"""Check if an index exists in Elasticsearch.
238+
239+
Args:
240+
index (ElasticsearchIndexType): The index name.
241+
**kwargs (object): Additional keyword arguments passed to the Elasticsearch client.
242+
243+
Returns:
244+
ElasticsearchResponseType: True if the index exists, False otherwise.
245+
246+
Raises:
247+
NotImplementedError: If not implemented by the subclass.
248+
"""
249+
raise NotImplementedError
250+
231251

232252
class AsyncElasticsearchPort:
233253
"""Async interface for Elasticsearch operations providing a standardized access pattern.
@@ -447,3 +467,23 @@ async def exists(
447467
NotImplementedError: If not implemented by the subclass.
448468
"""
449469
raise NotImplementedError
470+
471+
@abstractmethod
472+
async def index_exists(
473+
self,
474+
index: ElasticsearchIndexType,
475+
**kwargs: object,
476+
) -> ElasticsearchResponseType:
477+
"""Check if an index exists in Elasticsearch.
478+
479+
Args:
480+
index (ElasticsearchIndexType): The index name.
481+
**kwargs (object): Additional keyword arguments passed to the Elasticsearch client.
482+
483+
Returns:
484+
ElasticsearchResponseType: True if the index exists, False otherwise.
485+
486+
Raises:
487+
NotImplementedError: If not implemented by the subclass.
488+
"""
489+
raise NotImplementedError

0 commit comments

Comments
 (0)