gpt4 book ai didi

elasticsearch - 在ElasticSearch中查询多个字段和条件

转载 作者:行者123 更新时间:2023-12-03 02:03:59 26 4
gpt4 key购买 nike

在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

最佳答案

您可以为此使用 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
}
}
}
]
}
}
}
}
}

关于elasticsearch - 在ElasticSearch中查询多个字段和条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28665399/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com