Skip to content

Instantly share code, notes, and snippets.

@shunkino
Last active November 27, 2018 18:01
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 shunkino/d8b75b7e3102a398b329e4cf3ed38a8f to your computer and use it in GitHub Desktop.
Save shunkino/d8b75b7e3102a398b329e4cf3ed38a8f to your computer and use it in GitHub Desktop.
query to moloch example for my blog
from elasticsearch import Elasticsearch
es = Elasticsearch(['elasticsearch:9200'])
response = es.search(
index="sessions2-181016",
body={
"size": 0,
"query": {
"bool": {
"filter": {
"bool": {
"must": {
"term": {
"tags": "sample"
}
},
"should": [
{
"term": {
"dstPort": "80"
}
},
{
"term": {
"dstPort": "443"
}
}
]
}
}
}
},
"aggs": {
"agg_terms_dstIp": {
"terms": {
"field": "dstIp",
"size": 100
}
}
}
}
, request_timeout=100)
type(response)
response["aggregations"]["agg_terms_dstIp"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment