Skip to content

Instantly share code, notes, and snippets.

@dvas0004
Last active September 13, 2016 07:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvas0004/75db6e77369b83265fa8d83dd354bfaa to your computer and use it in GitHub Desktop.
Save dvas0004/75db6e77369b83265fa8d83dd354bfaa to your computer and use it in GitHub Desktop.
elasticsearch scan api snippet
from elasticsearch import Elasticsearch
from elasticsearch import helpers
res = es.search(index="filebeat-*", body={"filter": {"and": [{"range": {"@timestamp": {"gte": formattedBeginTime, "lte": formattedEndTime}}},
{"query": {"term": {"Type": "TRAFFIC"}}}]}}, size=0)
hits = res['hits']['total']
print "Processing {} documents".format(hits)
res = helpers.scan(es,
query={"filter": {"and": [{"range": {"@timestamp": {"gte": formattedBeginTime, "lte": formattedEndTime}}},
{"query": {"term": {"Type": "TRAFFIC"}}}]}},
index="filebeat-*", scroll=u'480m'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment