ElasticSearch7.0支持使用sql语法查询的方式,但是主子表的查询是不支持的
sql查询语句里面如果含有join字段会报如下错误
{
"error" : {
"root_cause" : [
{
"type" : "verification_exception",
"reason" : "Found 1 problem\nline 1:8: Cannot use field [relation_field] with unsupported type [join]"
}
],
"type" : "verification_exception",
"reason" : "Found 1 problem\nline 1:8: Cannot use field [relation_field] with unsupported type [join]"
},
"status" : 400
}
所以就没办法使用一句sql查询出来,但是它是支持sql+dsl混合查询的,所以可以把主子表的查询条件放到dsl里面和sql混在一起,如下
POST /_sql?format=json
{
"query":"select id from \"result\" limit 100",
"filter":{
"has_parent": {
"parent_type": "logs",
"query": {
"term": {
"port": 80
}
}
}
}
}
返回
这样就可以解决ElasticSearch7.0使用sql语法查询主子表结构了