File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
optimade/server/entry_collections Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -130,9 +130,14 @@ def create_elastic_index_from_mapper(
130130
131131 def __len__ (self ):
132132 """Returns the total number of entries in the collection."""
133+ from elasticsearch .exceptions import NotFoundError
133134 from elasticsearch_dsl import Search
134135
135- return Search (using = self .client , index = self .name ).execute ().hits .total .value
136+ try :
137+ return Search (using = self .client , index = self .name ).execute ().hits .total .value
138+ except NotFoundError :
139+ # If the collection does not exist, return 0, behaving similarly to MongoDB
140+ return 0
136141
137142 def insert (self , data : list [EntryResource | dict ]) -> None :
138143 """Add the given entries to the underlying database.
You can’t perform that action at this time.
0 commit comments