Firebase 为什么我的Firestore查询需要索引字段的这种特定顺序?

Firebase 为什么我的Firestore查询需要索引字段的这种特定顺序?,firebase,google-cloud-firestore,Firebase,Google Cloud Firestore,我对Firestore有以下查询: const query = await firestore.collection(`/records`) .where("targetId", "==", someId) .where("location", "==", someLocation) .where("dayCode", ">=&quo

我对Firestore有以下查询:

const query = await firestore.collection(`/records`)
        .where("targetId", "==", someId)
        .where("location", "==", someLocation)
        .where("dayCode", ">=", domeDay);
运行时,它要求索引:
location ASC、targetId ASC、dayCode ASC

我已经有了相同的索引,但字段的顺序不同,因此为了尝试重新使用它,我对查询重新排序,但它仍然要求相同的特定顺序。

为什么此查询需要在索引字段中进行此特定排序?

请共享您的Firestore数据和索引配置。此外,我会尝试使用
firestore.collection('records')
(不带前导的
/
),谢谢您的评论。需要明确的是:我对查询没有问题,它工作得很好,索引也很好。我在问为什么索引需要这种特定的排序:
location,targetId,dayCode
,而不是
targetId,location,dayCode
您已经有了哪些特定的索引,您希望Firestore使用这些索引来完成此查询?@FrankvanPuffelen:我以前有过
targetId升序dayCode升序位置升序
该索引是不够的。本质上:Firestore需要有一个索引,它可以通过立即查找(无索引扫描)找到结果的起始点,然后从该起始位置以单个流的形式返回结果。所以你肯定需要一个
dayCode
最后一个的索引,因为你有一个范围条件。如果您在
位置、targetId、location、dayCode ASC上有索引,Firestore可能会使用该索引,因为它可能会反转
=
条件。我不完全确定它是否会这样做,因此不会发布答案。请共享您的Firestore数据和索引配置。此外,我会尝试使用
firestore.collection('records')
(不带前导的
/
),谢谢您的评论。需要明确的是:我对查询没有问题,它工作得很好,索引也很好。我在问为什么索引需要这种特定的排序:
location,targetId,dayCode
,而不是
targetId,location,dayCode
您已经有了哪些特定的索引,您希望Firestore使用这些索引来完成此查询?@FrankvanPuffelen:我以前有过
targetId升序dayCode升序位置升序
该索引是不够的。本质上:Firestore需要有一个索引,它可以通过立即查找(无索引扫描)找到结果的起始点,然后从该起始位置以单个流的形式返回结果。所以你肯定需要一个
dayCode
最后一个的索引,因为你有一个范围条件。如果您在
位置、targetId、location、dayCode ASC上有索引,Firestore可能会使用该索引,因为它可能会反转
=
条件。我不完全确定它是否会这样做,因此不会发布答案。