在ElasticSearch中,可以在一个查询中转换此SQL吗?
SELECT * FROM table WHERE state IN ('NY', 'CA', 'FL') AND grade IN ('GOOD', 'BAD') AND active = 'YES' AND quantity > 100 AND quantity < 200
答案 0 :(得分:1)
您可以将 filtered
query 与 bool
filter 一起使用
{
"query" : {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"bool" : {
"must" : [{
"terms" : {
"state" : [
"NY",
"CA",
"FL"
]
}
},
{
"terms" : {
"grade" : [
"GOOD",
"BAD"
]
}
},
{
"term" : {
"active" : "YES"
}
},
{
"range" : {
"quantity" : {
"gt" : 100,
"lt" : 200
}
}
}
]
}
}
}
}
}