我正在使用Nest Elastic并使用Head插件构建布尔搜索的查询,我正在组合多个查询
关于DB结构和弹性映射的注意事项
-
数据库中的每个文档都链接到特定的profileId
反过来又具有多个属性
-
每个文档都有多个与其关联的属性值
在这个查询中,我试图获取所有具有特定配置文件和属性值的文档>30,记住该属性应该仅具有属性Id 2。
SQL查询:
选择平均*,d、 文档d内部联接attributeValue av的名称
在…上
d、 文档Id=平均文档Id
其中d.profileid=1并且av。AttributeId=2,平均值。内部值>30
弹性查询
{ "query": {
"bool": {
"must": [
{
"term": { "Document.profileid": "1" }
}
,
{
"term": {"Document.lstChildren.AttributeID": "2" }
}
,
{
"range": { "Document.lstChildren.IntValue": { "gt": "30"} }
}
,
{
"match_all": { }
}
],
"must_not": [ ],
"should": [ ]
}
}, "from": 0, "size": 10, "sort": [ ], "facets": { }
}
问题
结果还包含具有以下属性值的文档
-
属性值=3,attributeId=2(值<30)
-
属性值=34,但attributeId不同于2
(不正确)
此文件不能包含在内,因为它不能满足我的需求。
如何构建此查询?