使用elasticsearch-dsl-py查询时间戳范围

时间:2019-10-18 14:48:31

标签: python elasticsearch elasticsearch-dsl elasticsearch-dsl-py

我有一个Elasticsearch范围查询,我想将其转换为elasticsearch-dsl

Elasticsearch Python API

{"range": 
    {"@timestamp": 
        {"gte": 1570258800000, 
         "lte": 1571036400000, 
         "format": "epoch_millis"
        }
     }
 }

Elasticsearch-DSL-Py查询?

from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search

client = Elasticsearch(<connection_details>)

s = Search(using=client, index="my-index") \
    .query("???")

2 个答案:

答案 0 :(得分:1)

尝试一下:

from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search

client = Elasticsearch(<connection_details>)

s = Search(using=client, index="my-index") \
    .filter('range' ,  **{'@timestamp': {'gte': 1570258800000 , 'lt': 1571036400000, 'format' : 'epoch_millis'}})

答案 1 :(得分:0)

s = s.query('range', **{'@timestamp': {'gte': ...}})

希望这会有所帮助