elasticsearch-query
Run queries against Kibana's Elasticsearch that gets logs from Logstash. Forked from Wikia's kibana.py.
pip install elasticsearch-query
Basic Usage
from elasticsearch_query import ElasticsearchQuery
es_query = ElasticsearchQuery(es_host='es.prod', since=12345, period=900, index_prefix='logstash-my-app')
es_host needs to be specified with a host of Elasticsearch instance to connect.
Provide either since (absolute timestamp) or period (last N seconds):
since: UNIX timestamp data should be fetched since (if None, then period specifies the last n seconds).period: period (in seconds) before now() to be used when since is empty (defaults to last 15 minutes).
index_prefix argument will be used to build indices names to query in.
They should follow the index-name-YYYY.MM.DD naming convention, e.g. 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: query to be run against log messages (ex. {"@message": "Foo Bar DB queries"}).limit: the number of results (defaults to 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: query string to be run against log messages (ex.@message:"^PHP Fatal").fields: optional list of fields to fetchlimit: the number of results (defaults to 10).
query_by_sql
Returns data matching the given SQL query.
This feature requires non-OSS version of Elasticsearch ("To be clear, while the X-Pack source code is now available in the public repositories, it isn’t under an Open Source license").
es_query.query_by_sql(sql='SELECT host FROM "app-requests" WHERE host = \'app2.prod\'')
sql: SQL query to be run
count
Returns number of matching entries
es_query.count(query='@message:"^PHP Fatal"')
Integration tests
elasticsearch-query comes with integration tests suite. .travis.yml will install elasticsearch OSS version and run them.
But you can also run it locally. Simply pass ES_TEST_HOST=<elasticsearch IP> env variable when running tests (make test).
Metadata
Release files for elasticsearch-query 2.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| elasticsearch-query-2.4.0.tar.gz | 6.4 kB | Without provenance | Details for elasticsearch-query-2.4.0.tar.gz |
Release files / elasticsearch-query-2.4.0.tar.gz
| Download URL | elasticsearch-query-2.4.0.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1b90afd45f5ad0427af87583f9d3ce1c699aa09043fc0f72d36e6d666a968821
|
|
BLAKE2b-256 checksum How to use checksums |
dc4a86ce2ef588b3815c751f721b859462edd95e44e9e2ed64e431049f7468fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7
|
Security for elasticsearch-query 2.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.