First, you need to index some test data:
DELETE /test
{}
POST /test/doc/
{"price": 10, "type": "widget"}
POST /test/doc/
{"price": 15, "type": "cog"}
POST /test/doc/
{"price": 55, "type": "widget"}
POST /test/doc/
{"price": 61, "type": "foo"}
POST /test/doc/
{"price": 70, "type": "foo"}
POST /test/doc/
{"price": 99, "type": "foo"}
POST /test/doc/
{"price": 160, "type": "foo"}
POST /test/doc/
{"price": 170, "type": "eggplant"}
POST /test/doc/
{"price": 1, "type": "eggplant"}
POST /test/doc/
{"price": 12, "type": "eggplant"}
POST /test/doc/
{"price": 112, "type": "eggplant"}
POST /test/doc/
{"price": 99, "type": "eggplant"}
POST /test/doc/_search
{
"aggs" : {
"prices" : {
"histogram" : {
"field" : "price",
"interval" : 20,
"min_doc_count": 0
}
}
},
"size": 0
}
key | document count |
---|---|
0 | 4 |
20 | 0 |
40 | 1 |
60 | 2 |
80 | 2 |
100 | 1 |
120 | 0 |
140 | 0 |
160 | 2 |
Which can then be passed into something like Gnuplot:
plot data using 1:2 with lines
POST /test/doc/_search
{
"aggs" : {
"my_terms_agg" : {
"terms" : {
"field" : "type"
}
}
},
"size": 0
}
key | document count |
---|---|
eggplant | 5 |
foo | 4 |
widget | 2 |
cog | 1 |