英文:
How to query all entities those array type field contains at least one element of the given array using java API?
问题
我有一个具有数组类型字段的GCP数据存储实体,其中包含一个元素列表,类似于[1,2,3]
示例:
@Entity
public class TestEntity{
@Id
String id;
List<String> data;
}
我需要使用GCP Java API构建一个查询,以选择所有具有给定数组中至少一个元素的实体。
示例:
两个实体:
1:[1,2,3]
2:[1,4,5]
对于输入,我希望选择:
[1,2] - 1, 2;
[2] - 1
EntityQuery.Builder queryBuilder =
Query.newEntityQueryBuilder().setKind("testEntity");
queryBuilder.setFilter(....)
我在API中没有看到类似于“包含”或“在内”的过滤器。如何构建这样的查询?
英文:
I have a GCP datastore entity that has an array type field that contains a list of elements, like [1,2,3]
Example:
@Entity
public class TestEntity{
@Id
String id;
List<String> data;
}
I need to build a query using GCP java API to select all entities that have at least one element of the given array in the field.
Example:
two entities:
1: [1,2,3]
2: [1,4,5]
I expect to select for input:
[1,2] - 1, 2;
[2] - 1
EntityQuery.Builder queryBuilder =
Query.newEntityQueryBuilder().setKind("testEntity");
queryBuilder.setFilter(....)
I do not see a filter like "contains" or "is in" in the API. How can I build such a query?
答案1
得分: 0
Datastore模式对每个索引每次仅索引每个唯一的数组属性值。因此,要查询数组是否包含某个值,请使用等值筛选器。
.setFilter(PropertyFilter.eq(property,value))
英文:
Datastore mode indexes each unique array property value once per index. Thus to query if an array contains a value use an equality filter. [1]
.setFilter(PropertyFilter.eq(property,value))
[1] https://cloud.google.com/datastore/docs/concepts/queries#array_values
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论