Python Elasticsearch api
pip install elasticsearch
from elasticsearch import Elasticsearch
es = Elasticsearch([{'host':'10.10.13.12','port':9200}])
es.search(index='logstash-2015.08.20', q='http_status_code:5* AND server_name:"web1"', from_='124119')
- index - 索引名
- q - 查询指定匹配 使用Lucene查询语法
- from_ - 查询起始点 默认0
- doc_type - 文档类型
- size - 指定查询条数 默认10
- field - 指定字段 逗号分隔
- sort - 排序 字段:asc/desc
- body - 使用Query DSL
- scroll - 滚动查询
In[52]: es.count(index='logstash-2015.08.21', q='http_status_code:500')
Out[52]:{u'_shards':{u'failed':0, u'successful':5, u'total':5}, u'count':17042}
- 滚动demo
# Initialize the scroll
page = es.search(
index ='yourIndex',
doc_type ='yourType',
scroll ='2m',
search_type ='scan',
size =1000,
body ={
# Your query's body
}) sid = page['_scroll_id']
scroll_size = page['hits']['total'] # Start scrolling
while(scroll_size >0):
print "Scrolling..."
page = es.scroll(scroll_id = sid, scroll ='2m')
# Update the scroll ID
sid = page['_scroll_id']
# Get the number of results that we returned in the last scroll
scroll_size = len(page['hits']['hits'])
print "scroll size: "+ str(scroll_size)
# Do something with the obtained page
- Query DSL
"range":{
"money":{
"gt":20,
"lt":40
}
}
{
"bool":{
"must":[],
"should":[],
"must_not":[],
}
}
- term单过滤
{
"terms":{
"money":20
}
}
- terms复数版本,允许多个匹配条件
{
"terms":{
"money": [20,30]
}
}
{
"regexp": {
"http_status_code": "5.*"
}
}
- match 精确匹配
{
"match":{
"email":"123456@qq.com"
}
}
- multi_match 多字段搜索
{
"multi_match":{
"query":"11",
"fields":["Tr","Tq"]
}
}
- 获取最近一小时的数据
{'query':
{'filtered':
{'filter':
{'range':
{'@timestamp':{'gt':'now-1h'}}
}
}
}
}
- 条件过滤查询
{
"query":{
"filtered":{
"query":{"match":{"http_status_code":500}},
"filter":{"term":{"server_name":"vip03"}}
}
}
}
- Terms Facet 单字段统计
{'facets':
{'stat':
{'terms':
{'field':'http_status_code',
'order':'count',
'size':50}
}
},
'size':0
}
- 一次统计多个字段
{'facets':
{'cip':
{'terms':
{'fields':['client_ip']}},
'status_facets':{'terms':{'fields':['http_status_code'],
'order':'term',
'size':50}}},
'query':{'query_string':{'query':'*'}},
'size':0
}
- 多个字段一起统计
{'facets':
{'tag':
{'terms':
{'fields':['http_status_code','client_ip'],
'size':10
}
}
},
'query':
{'match_all':{}},
'size':0
}
{
"facets": {
"0": {
"date_histogram": {
"field": "@timestamp",
"interval": "5m"
},
"facet_filter": {
"fquery": {
"query": {
"filtered": {
"query": {
"query_string": {
"query": "*"
}
},
"filter": {
"bool": {
"must": [
{
"range": {
"@timestamp": {
'gt': 'now-1h'
}
}
},
{
"exists": {
"field": "http_status_code.raw"
}
},
# --------------- -------
# 此处加匹配条件
]
}
}
}
}
}
}
}
},
"size": 0
}
{
"query": {
"query_string": {"query": "backend_name:baidu.com"}
}
},
Python Elasticsearch api的更多相关文章
- Python Elasticsearch api,组合过滤器,term过滤器,正则查询 ,match查询,获取最近一小时的数据
Python Elasticsearch api 描述:ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.下 ...
- 用 Identity Server 4 (JWKS 端点和 RS256 算法) 来保护 Python web api
目前正在使用asp.net core 2.0 (主要是web api)做一个项目, 其中一部分功能需要使用js客户端调用python的pandas, 所以需要建立一个python 的 rest api ...
- Python DB API 连接数据库
Python DB API Mysql,Oracle,SqlServer 不关闭,会浪费资源.
- Python调用API接口的几种方式 数据库 脚本
Python调用API接口的几种方式 2018-01-08 gaoeb97nd... 转自 one_day_day... 修改 微信分享: 相信做过自动化运维的同学都用过API接口来完成某些动作.AP ...
- Python调用API接口的几种方式
Python调用API接口的几种方式 相信做过自动化运维的同学都用过API接口来完成某些动作.API是一套成熟系统所必需的接口,可以被其他系统或脚本来调用,这也是自动化运维的必修课. 本文主要介绍py ...
- 如何用 Python 和 API 收集与分析网络数据?
摘自 https://www.jianshu.com/p/d52020f0c247 本文以一款阿里云市场历史天气查询产品为例,为你逐步介绍如何用 Python 调用 API 收集.分析与可视化数据.希 ...
- Elasticsearch API响应的一些常用选项
我们可以点击Elasticsearch API以获取所需的响应,但是如果要修改API响应,以便我们更改显示格式或过滤掉某些字段,然后我们可以将这些选项与查询一起应用. 有一些常见的选项可以适用于API ...
- ElasticSearch API 简要介绍
调用其API会返回很多信息,例如集群的信息,节点的信息等 检查集群的状态----Restful API说明 1:检查集群状态信息 2:管理集群 3:执行 增删改查 命令 4:执行高级命令 Restfu ...
- 如何查看python 的api
python 搭建好python开发环境后,怎么查看api文档呢? 其实很简单: 首先打开命令行,在dos窗口输入: python -m pydoc -p 4895 python -m pydoc - ...
随机推荐
- GMM算法k-means算法的比较
1.EM算法 GMM算法是EM算法族的一个具体例子. EM算法解决的问题是:要对数据进行聚类,假定数据服从杂合的几个概率分布,分布的具体参数未知,涉及到的随机变量有两组,其中一组可观测另一组不可观测. ...
- Jquery easyui datagrid 删除多行问题
http://www.cnblogs.com/Dtscal/archive/2012/07/04/2576639.html 最近模仿了刘冬大哥的<开源框架完美组合之Spring.NET + NH ...
- 千万不要误用 java 中的 HashCode 方法
刚才debug追堆栈的时候发现一个很奇怪的问题 我用IE8和Google的浏览器访问同一个地址 Action的 scope="session" 也设置了 而且两个浏览器提交的参数m ...
- WGS84、Web墨卡托、火星坐标、百度坐标互转
转自:1.http://blog.csdn.net/wildboy2001/article/details/12031351 2.http://kongxz.com/2013/10/wgs-cgj/ ...
- 使用 PHP 和 Apache Solr 实现企业搜索
原文链接:http://www.ibm.com/developerworks/cn/opensource/os-php-apachesolr/ http://blog.csdn.net/hzcyc ...
- C++中的异常处理(二)
C++中的异常处理(二) 标签: c++C++异常处理 2012-11-24 20:56 1713人阅读 评论(2) 收藏 举报 分类: C++编程语言(24) 版权声明:本文为博主原创文章,未经 ...
- 《深入PHP与jQuery开发》读书笔记——Chapter2
Pro PHP and jQuery Chapter2 总结 1.理解jQuery脚本的基本行为 jQuery事实上沿用了JavaScript的那一套东西,几乎所有方法都支持链式调用,也就是说方法可以 ...
- 唐巧的iOS技术博客选摘
1. 那些被遗漏的objective-c保留字:http://blog.devtang.com/blog/2013/04/29/the-missing-objc-keywords/ 2. 使用cr ...
- CocoStudio基础教程(1)创建UI并载入到程序中
1.概述 CocoStudio的使用无疑是cocos2d-x 3.0的重要组成部分,接下来我们用它来创建一组UI,并将其读入到程序中显示出来.先上效果图: 2.导出 在导出之前,最好先创建一个新的工程 ...
- java的一段对象数据类型映射的代码
try { List<GateMetaPO> listGateInfoPO = majorGateReaderService.queryForAggregateBy( chapter); ...