diff --git a/dp3/api/routers/entity.py b/dp3/api/routers/entity.py index ccddcc27..1c33ac35 100644 --- a/dp3/api/routers/entity.py +++ b/dp3/api/routers/entity.py @@ -432,8 +432,14 @@ async def get_entity_type_eids( # Apply sorting if specified if sort_criteria: - # Prepare sort specification with 'last.' prefix for snapshot data - sort_spec = [("last." + attr, direction) for attr, direction in sort_criteria] + # 'eid' uses snapshot _id storage order so standalone EID sorts can use + # the _id index. This intentionally differs from natural EID order for + # some strings (bucket suffixes) and signed integers (binary encoding). + # Other attributes live under 'last.' + sort_spec = [ + ("_id" if attr == "eid" else "last." + attr, direction) + for attr, direction in sort_criteria + ] cursor = cursor.sort(sort_spec) cursor_page = cursor.skip(skip).limit(limit)