ELK架构中ES-DSL
API接口,可以通过python程序进行调用查询。但是某人的query只能查询到10条记录,而且如何通过给定的开始时间戳及结束的时间戳来进行快速过滤呢?详见以下代码示例:
client =
Elasticsearch(['http://127.0.0.1:9200'])
my_index = 'logstash-' +
str(time.strftime('%Y.%m.%d', time.localtime(end_time)))
search_terms = Search(using =
client, index = my_index).filter('range', ** {'@timestamp':
{'gte':'2016-04-20T10:18:48.946Z','lt':'2016-04-20T10:23:48.946Z'}})
\
.query('match', channel_name =
channel)[0:1000]
response =
search_terms.execute()
关键点解释:
1、连接ES的本机端口;
2、设置index索引,这里的关键字是'logstash+日期'
3、调用Search方法,关键在于先filter,后query.
4、filter的时间戳过滤方法为**{'@timestamp':{'gte': end_time, 'lt':beg_time}} 为
关键点解释:
1、连接ES的本机端口;
2、设置index索引,这里的关键字是'logstash+日期'
3、调用Search方法,关键在于先filter,后query.
4、filter的时间戳过滤方法为**{'@timestamp':{'gte': end_time, 'lt':beg_time}} 为
