绊脚石乃是进身之阶。

ES 如何实现 SQL 查询条件 (name=1 or name=2 ) and (status=1 or status =2)

Elasticsearch | 作者 KuboKang520 | 发布于2019年12月24日 | 阅读数:3833

使用ES 查询 实现 Sql 查询条件 比如 select * from user where (name=1 or name=2 ) and (status=1 or status =2) 这种条件 。 ES是如何实现的 ? 考虑性能呢 ?
已邀请:

novia - 1&0

赞同来自: ppppenger

用es的_sql/translate特性,通过sql反查es语句
 
POST _sql/translate
{
"query": "select * from log_5c54dd7a87604fa195aad3224ab93a49 where (test=1 or test=2) and (test2=1 or test2 =2)"
}
返回
{
"size": 1000,
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"term": {
"test.keyword": {
"value": 1,
"boost": 1
}
}
},
{
"term": {
"test.keyword": {
"value": 2,
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
{
"bool": {
"should": [
{
"term": {
"test2.keyword": {
"value": 1,
"boost": 1
}
}
},
{
"term": {
"test2.keyword": {
"value": 2,
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"_source": {
"includes": [
"input.type",
"test",
"test2"
],
"excludes": [

]
},
"docvalue_fields": [
{
"field": "@timestamp",
"format": "epoch_millis"
}
],
"sort": [
{
"_doc": {
"order": "asc"
}
}
]
}

mobikarl

赞同来自:

布尔查询,考虑性能加filter

要回复问题请先登录注册