diff --git a/elasticsearch_dsl/_async/document.py b/elasticsearch_dsl/_async/document.py index 1ff68a79..f89cff2f 100644 --- a/elasticsearch_dsl/_async/document.py +++ b/elasticsearch_dsl/_async/document.py @@ -134,7 +134,7 @@ async def get( using: Optional[AsyncUsingType] = None, index: Optional[str] = None, **kwargs: Any, - ) -> Optional[Self]: + ) -> Self: """ Retrieve a single document from elasticsearch using its ``id``. @@ -144,12 +144,11 @@ async def get( :arg using: connection alias to use, defaults to ``'default'`` Any additional keyword arguments will be passed to - ``Elasticsearch.get`` unchanged. + ``Elasticsearch.get`` unchanged. If the given ``id`` is not found, + a ``NotFoundError`` exception is raised. """ es = cls._get_connection(using) doc = await es.get(index=cls._default_index(index), id=id, **kwargs) - if not doc.get("found", False): - return None return cls.from_es(doc) @classmethod diff --git a/elasticsearch_dsl/_sync/document.py b/elasticsearch_dsl/_sync/document.py index abcda3a3..f842f4e8 100644 --- a/elasticsearch_dsl/_sync/document.py +++ b/elasticsearch_dsl/_sync/document.py @@ -128,7 +128,7 @@ def get( using: Optional[UsingType] = None, index: Optional[str] = None, **kwargs: Any, - ) -> Optional[Self]: + ) -> Self: """ Retrieve a single document from elasticsearch using its ``id``. @@ -138,12 +138,11 @@ def get( :arg using: connection alias to use, defaults to ``'default'`` Any additional keyword arguments will be passed to - ``Elasticsearch.get`` unchanged. + ``Elasticsearch.get`` unchanged. If the given ``id`` is not found, + a ``NotFoundError`` exception is raised. """ es = cls._get_connection(using) doc = es.get(index=cls._default_index(index), id=id, **kwargs) - if not doc.get("found", False): - return None return cls.from_es(doc) @classmethod