【发布时间】:2018-11-06 03:34:40
【问题描述】:
下面的查询是我想用elasticsearch-dsl-py构造的,但是不知道怎么做。
GET /my_index/_search
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"term": {
"status": "published"
}
},
{
"or": {
"filters": [
{
"range": {
"start_publication": {
"lte": "2015-02-17T03:45:00.245012+00:00"
}
}
},
{
"missing": {
"field": "start_publication"
}
}
]
}
},
{
"or":{
"filters": [
{
"range": {
"end_publication": {
"gte": "2015-02-17T03:45:00.245012+00:00"
}
}
},
{
"missing": {
"field": "end_publication"
}
}
]
}
}
]
}
}
}
}
}
使用elasticsearch-dsl-py,这是我能得到的最接近的,但它不一样。 '|'运算符变成了 'should' 子句,而不是 'OR'。
client = Elasticsearch()
now = timezone.now()
s = Search(using=client,
index="my_index"
).filter(
"term", status=PUBLISHED
).filter(
F("range", start_publication={"lte": now}, ) |
F("missing", field="start_publication")
).filter(
F("range", end_publication={"gte": now}, ) |
F("missing", field="end_publication")
)
response = s.execute()
【问题讨论】:
标签: python elasticsearch boolean dsl