下面的查询是我想要使用elasticsearch-dsl-py构造的,但我不知道怎么做。
GET /my_index/_search
{
"query": {
"filtered": {
"filter": {
"bool": {
"or": {
"filters": [
{
"term": {
"status": "a"
},
"term": {
"x_status": "a"
},
}
]
}
}
}
}
}
}我只想以SQL格式执行如下查询
select * from my_index where status = "a" or x_status="a"发布于 2020-08-18 21:31:21
我不确定您运行的是哪个版本的ES,但只知道filtered has been replaced by bool在很久以前的版本5中。所以您的查询可以重写为:
GET /my_index/_search
{
"query": {
"bool": {
"should": [
{
"term": {
"status": "a"
}
},
{
"term": {
"x_status": "a"
}
}
]
}
}
}使用elasticsearch-dsl-py,这可以转化为:
s = Search()
s = s.query('bool', should=[Q('term', status='a'), Q('term', x_status='a')])https://stackoverflow.com/questions/63468866
复制相似问题