Types Description: parent type
1)Parent Type: "product"
2)childType : "ratings"
问题描述:我有一个es查询(query-1)工作正常并从父类型(产品)中获取结果,现在我添加了一个新类型(评级),并使新类型的子项为“product”,我需要扩展此现有查询,其中新结果应根据匹配的子(评级)类型的字段值进行排序。
查询-1:
{
"bool" : {
"must" : [ {
"has_parent" : {
"query" : {
"bool" : {
"must" : {
"term" : {
"searchable" : "true"
}
}
}
},
"parent_type" : "supplierparent",
"inner_hits" : { }
}
}, {
"bool" : {
"must" : {
"query" : {
"simple_query_string" : {
"query" : "rice"
}
}
}
}
}, {
"nested" : {
"query" : {
"term" : {
"productStatusList.status" : "Approved"
}
},
"path" : "productStatusList"
}
} ]
}
}
我认为应该有更好的方法来执行此操作,就像我们使用nested
文档的属性排序一样。但是,可以使用父子关系进行排序的一种方法是当前类型的属性。
因为它们现在是完全不同的文档存储,所以不可能使用子属性来对父类进行排序。同一个父文档可能有多个子文档,这会在排序结果时产生歧义。