Skip to content

Instantly share code, notes, and snippets.

@loicbertron
Created December 12, 2012 17:43
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 loicbertron/4269916 to your computer and use it in GitHub Desktop.
Save loicbertron/4269916 to your computer and use it in GitHub Desktop.
Apache logs and Faceted query
curl -XGET http://127.0.0.1:19200/logstash-2012.12.12/apache/_search?pretty=1 -d '{
"query" : { "match" : {"@fields.username" : "user1"}},
"facets" : { "ip" : { "terms" : {"field" : "client"} } }
}'
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 7.142037,
"hits" : [ {
"_index" : "logstash-2012.12.12",
"_type" : "apache",
"_id" : "oRBFX-S9RWWzvXL28t-YTA",
"_score" : 7.142037, "_source" : {"@source":"file://xyz.com/var/log/apache2/access_json.log","@tags":[],"@fields":{"client":"192.168.1.1","username":"user1","duration_usec":590258,"status":103,"request":"myfile1.mp4","method":"GET","referrer":"-"},"@timestamp":"2012-12-12T09:19:45-0500","@source_host":"xyz.com","@source_path":"/var/log/apache2/access_json.log","@type":"apache"}
} ]
},
"facets" : {
"ip" : {
"_type" : "terms",
"missing" : 0,
"total" : 1,
"other" : 0,
"terms" : [ {
"term" : "192.168.1.1",
"count" : 1
} ]
}
}
}
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 4813,
"max_score" : 1.0,
"hits" : [ {
"_index" : "logstash-2012.12.12",
"_type" : "apache",
"_id" : "ueS9_487Tp6tJUGMOgec1Q",
"_score" : 1.0, "_source" : {"@source":"file://xyz.com/var/log/apache2/access_json.log","@tags":[],"@fields":{"client":"192.168.1.1","username":"user1","duration_usec":590258,"status":103,"request":"myfile1.mp4","method":"GET","referrer":"-"},"@timestamp":"2012-12-12T09:19:45-0500","@source_host":"xyz.com","@source_path":"/var/log/apache2/access_json.log","@type":"apache"}
}, {
"_index" : "logstash-2012.12.12",
"_type" : "apache",
"_id" : "ROqX4p71QB6DKw6sg6b1CQ",
"_score" : 1.0, "_source" : {"@source":"file://xyz.com/var/log/apache2/access_json.log","@tags":[],"@fields":{"client":"192.168.1.2","username":"user2","duration_usec":1321907,"status":103,"request":"myfile2.mp4","method":"GET","referrer":"-"},"@timestamp":"2012-12-12T09:19:48-0500","@source_host":"xyz.com","@source_path":"/var/log/apache2/access_json.log","@type":"apache"}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment