# 查询接口中请求体相关说明

在进行构件筛选应用时,有时需基于多个条件组合进行高级查询。为满足这类查询,BIMFACE支持在查询符合条件的构件ID列表 (opens new window)接口中,通过body基于dsl进行高级查询。查询语句主要参考 Elasticseach的Query DSL (opens new window),可以简单看作是ES的DSL的子集,但部分关键字稍有改动。

例:

{
    "targetType":"file",
    "targetIds":["1124890692330272"],
    "query":{
       "boolOr" :  [
           { "match" : {"productID" : "KDKE-B-9947-#kL5"}},
           { "boolAnd" : [
               { "match" : {"productID" : "JODL-X-1937-#pV7"}},
               { "match" : {"price" : 30}}
             ]
           }
         ]
   }
}

等价于

SELECT elementId
FROM   XXX
WHERE  productID      = "KDKE-B-9947-#kL5"
  OR (     productID = "JODL-X-1937-#pV7"
       AND price     = 30 )

# 查询字段说明

字段 类型 必填 描述 示例
targetType String Y 查询目标类型,只能是file或integration file
targetIds String[] Y 查询目标ID列表 [“1124890692330272”]
query Object Y 查询条件实体,由match、contain、boolAnd、boolOr组成 ..
match Object N 精确匹配某个属性值 {“floor”:“F1”}
contain Object N 模糊匹配某个属性值 {“floor”:“1”}
in Object N 精确查询多个属性值的并集 {“floor”:["F1","F2","F3"]}
boolAnd Object[] N 逻辑与查询,支持嵌套 ..
boolOr Object[] N 逻辑或查询,支持嵌套 ..

# 查询示例

1.查询文件id为1124890692330272中,所有floor属性中包含F的elementId。对应body内可传入:

{
    "targetType":"file",
    "targetIds":["1124890692330272"],
    "query":{
        "contain":{
            "floor":"F"
        }
    }
}

2.查询文件id为1124890692330272中,所有floor属性为F11的elementId。对应body内可传入:

{
    "targetType":"file",
    "targetIds":["1124890692330272"],
    "query":{
        "match":{
            "floor":"F11"
        }
    }
}

3.查询文件id为1124890692330272中,所有floor属性包含F并且family为标准的elementId。对应body内可传入:

{
    "targetType":"file",
    "targetIds":["1124890692330272"],
    "query":{
        "boolAnd":[
            {"contain":{"floor":"F"}},
            {"match":{"family":"标准"}}
        ]
    }
}

4.查询文件id为1124890692330272中,所有floor属性为F1-F3或family为标准的elementId。对应body内可传入:

{
    "targetType":"file",
    "targetIds":["1124890692330272"],
    "query":{
        "boolOr":[
            {"in":{"floor":["F1","F2","F3"]}},
            {"match":{"family":"标准"}}
        ]
    }
}

5.较为复杂的查询示例

{
    "targetType":"file",
    "targetIds":["1124890692330272"],
    "query":{
        "contain":{
            "floor":"B01",
            "familyType":"标准"
        },
        "match":{"family":"family1"},
        "boolAnd":[
            {"match":{"categoryId":"id111"}},
			{"match":{"boundingBox.min.x":167899.9999999998}}
        ],
        "boolOr":[
            { "match" : {"productID" : "KDKE-B-9947-#kL5"}},
            { "boolAnd" : [
               { "match" : {"productID" : "JODL-X-1937-#pV7"}},
               { "match" : {"price" : 30}}
             ]
           }
        ]
    }
}