select * from tbl where col in ("value1", "value2")
-
es 中如何实现 sql 中的in,使用terms实现
-
语法如下:
term: {"field": "value"}
terms: {"field": ["value1", "value2"]}
例子一:
搜索articleID为KDKE-B-9947-#kL5或QQPX-R-3956-#aD8的帖子
GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"terms": {
"articleID": [
"KDKE-B-9947-#kL5",
"QQPX-R-3956-#aD8"
]
}
}
}
}
}
例子二
- 搜索结果仅仅搜索tag只包含java的帖子
GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"bool": {
"must": [
{
"term": {
"tag_cnt": 1
}
},
{
"terms": {
"tag": ["java"]
}
}
]
}
}
}
}
}