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 - ...
随机推荐
- bzoj 2815 灾难
首先假设我们定义x灭绝后y会灭绝,那么离y最近的x就为y的父亲节点,那么如果我们可以求出每个节点的父亲节点,我们就得到了一棵树,然后每个节点的灾难值就是子树的大小-1. 我们将出度数为0的节点的父亲节 ...
- 【poj1001】 Exponentiation
http://poj.org/problem?id=1001 (题目链接) 题意 求实数R的n次方,要求高精度. Solution SB题Wa了一下午,直接蒯题解. 高精度,小数点以及去前导后导零很麻 ...
- 【uoj150】 NOIP2015—运输计划
http://uoj.ac/problem/150 (题目链接) 题意 给出一棵树以及m个询问,可以将树上一条边的权值修改为0,求经过这样的修改之后最长的边最短是多少. Solution 老早就听说过 ...
- sql prompt5安装好了 也破解完成了 然后到SQL里面 还是没有提示 是为什么?
勾上这个,祝你成功!
- 单机redis多端口实例+keepalived高可用
一.实验环境说明 192.168.115.21(keepalived+redis) 192.168.115.95(keepalived+redis) VIP:192.168.115.99 二.安装re ...
- ecshop后台导航修改教程说明
ecshop后台导航修改教程说明 ECSHOP教程/ ecshop教程网(www.ecshop119.com) 2014-06-25 需要操作的文件为: 1.修改admin\includes\in ...
- 织梦DedeCMS删除所有栏目或文章后,新建ID不从1开始的解决方法
这个修改方法很简单,从模板无忧那里找到的,只需要在后台系统-SQL命令行工具里面运行以下语句即可,不用采用笨方法重新安装织梦CMS了. 删除所有栏目,新建ID从1开始: ALTER TABLE `de ...
- SQL防注入程序
1.在Global.asax.cs中写入: protected void Application_BeginRequest(Object sender,EventArgs e){ SqlIn ...
- linux init.d脚本编写模板
#!/bin/bash ### BEGIN INIT INFO # # Provides: location_server # Required-Start: $local_fs $remote_fs ...
- bootstrap-select搜索框输入中文
bootstrap-select 的搜索框无法输入中文,解决办法: 删除源码中这两行代码 that.$lis.not('.hidden, .divider, .dropdown-header').eq ...