对kibana的elasticsearch运行查询,该elasticsearch从logstash获取日志。

elasticsearch-quer的Python项目详细描述


弹性搜索查询

PyPIBuild Status

对kibana的elasticsearch运行查询,该elasticsearch从logstash获取日志。从Wikia's ^{}分叉。

pip install elasticsearch-query

基本用法

fromelasticsearch_queryimportElasticsearchQueryes_query=ElasticsearchQuery(es_host='es.prod',since=12345,period=900,index_prefix='logstash-my-app')

es_host需要指定一个要连接的ElasticSearch实例主机。

提供since(绝对时间戳)或period(最后N秒):

  • since:应该获取unix时间戳数据,因为(如果没有,那么period指定最后n秒)。
  • period:在since为空(默认为持续15分钟)时使用的before now()周期(秒)。

index_prefix参数将用于生成要查询的索引名称。 它们应该遵循index-name-YYYY.MM.DD命名约定,例如logstash-my-app-2014.08.19

get_rows

Returns data matching the given query (provided as a dict).

es_query.get_rows(match={"tags":'edge-cache-requestmessage'},limit=2000)
  • match:对日志消息运行的查询(例如{“@message”:“foo bar db querys”})。
  • limit:结果数(默认为10)。

query_by_string

Returns data matching the given query string (provided as a Lucene query).

es_query.query_by_string(query='@message:"^PHP Fatal"',limit=2000)es_query.query_by_string(query='@message:"^PHP Fatal"',fields=['@message','@es_query_host'],limit=2000)
  • query:对日志消息运行的查询字符串(例如@message:"^PHP Fatal")。
  • fields:要获取的字段的可选列表
  • limit:结果数(默认为10)。

query_by_sql

Returns data matching the given SQL query.

elasticsearch的requiresnon-oss版本的这一功能(“要清楚,虽然x-pack源代码现在在公共存储库中可用,但它不在开放源代码许可下”)。

es_query.query_by_sql(sql='SELECT host FROM "app-requests" WHERE host = \'app2.prod\'')

count

Returns number of matching entries

es_query.count(query='@message:"^PHP Fatal"')

集成测试

elasticsearch-query带有集成测试套件。.travis.yml将安装ElasticSearch OSS版本并运行它们。

但也可以在本地运行。运行测试时只需传递ES_TEST_HOST=<elasticsearch IP>env变量(make test)。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java为什么TestNG看到的是我的包而不是我的类?   java JSTL fn:子字符串之间?   java Android NotificationChannel与旧API的兼容性   java在循环内部或外部声明对象?   java刷新GziOutputStream,然后重置ByteArrayOutputStream安全吗?   子类中父类的java JAXB“重命名”属性   java Android,适配器getView中的NullPointerException   java网络适配器在与Oracle DB连接时无法建立连接   java创建没有实体的spring存储库   java将下面程序的输出提供给我,它只是没有点击。答案是63,我显然不明白   java禁用Android上的Firebase脱机功能   java如何从Maven扩展停止构建   java此代码显示在单击按钮之前获得的焦点