下面的查询是我想使用elasticsearch-dsl构建的,但是我不知道如何去做。
GET /my_index/_search
{
"query": {
"filtered": {
"filter": {
"bool": {
"should": [
{
"term": {
"status": "a"
},
"term": {
"status": "b"
},
"term": {
"status": "c"
}
}
]
}
}
}
}
}我只想以SQL格式执行如下查询
select * from my_index where status in ("a","b","c")使用elasticsearch-dsl-py,这是我所能得到的最接近的,但它是不一样的。
class MyIndex(Document):
status = Keyword() / Text()
MyIndex.search().filter('should', status=["a","b","c"])发布于 2020-08-14 10:46:44
另一种方法是使用带有数组的terms查询,因为每个数组元素都是隐式ORed。另外,我不确定您正在运行的ES的哪个版本,但是只知道很久以前版本5中的filtered has been replaced by bool。
GET /my_index/_search
{
"query": {
"bool": {
"filter": {
"terms": {
"status": ["a", "b", "c"]
}
}
}
}
}使用elasticsearch-dsl-py,这将转换为:
s = Search()
s = s.filter('terms', status=['a', 'b', 'c'])https://stackoverflow.com/questions/63411075
复制相似问题