我需要根据用户对象的类型过滤activities
属性的子对象。
我的用户对象模型
{
userId,
fistName,
lastName,
activities: [
{mode: 'Typ1', name: 'Some Name', "description": "Some Desc"},
{mode: 'Typ2', name: 'Some Name2', "description": "Some Desc2"},
{mode: 'Typ1', name: 'Some Name3', "description": "Some Desc3"}
]
}
查询弹性6.7时,我使用父子关系获取整个用户模型,但根据activities
中的特定值过滤了mode
为此,我创建了
PUT <my_index>/user/_mappings
{
"properties": {
"activities": {
"type": "join",
"relations": {
"activities": "activities.mode"
}
}
}
}
在查询...
GET <my_index>/user/_search
{
"size": 1000,
"query" : {
"bool": {
"must": [
{
"term": {
"userId": "123456"
}
}
],
"filter": {
"has_parent": {
"parent_type": "activities",
"query": {
"term": {
"activities.mode": "Typ1"
}
}
}
}
}
},
"_source": ["userId", "firstName", "lastName", "activities.mode", "activities.name"]
}
但是,在尝试上述查询后,我得到的是类似的东西...
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
这里的任何帮助将不胜感激