Google 不同属性的数据存储查询和排序

Google Datastore Query and Sort on different properties

我正在尝试使用 Google 的数据存储 API (Java11) 对与用作过滤器的字段不同的字段上的数据进行排序。我收到以下错误

inequality filter property and first sort order must be the same

示例: 数据:

Name: Toronto, Temperature: 30
Name: New York, Temperature: 70
Name: Montreal, Temperature: 10

数据存储区查询:

Query<Entity> query = Query.newEntityQueryBuilder()
        .setKind("Cities")
                .addOrderBy(OrderBy.asc("Name"))
        .setFilter(CompositeFilter.and(
            PropertyFilter.ge("Temperature", 30)))
        .build();

应与以下内容相同:

SELECT name,temperature FROM cities WHERE temperature >= '30' ORDER BY name;

有没有办法在 Datastore 中执行如此简单的查询?

不,你必须自己求助。如 https://cloud.google.com/datastore/docs/concepts/queries#sort_orders:

的注释框中所述

"Note: Because of the way Datastore mode executes queries, if a query specifies inequality filters on a property and sort orders on other properties, the property used in the inequality filters must be ordered before the other properties."