Skip to content

Instantly share code, notes, and snippets.

@johtani
Created January 21, 2015 07:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johtani/9687fb3cfb249750910d to your computer and use it in GitHub Desktop.
Save johtani/9687fb3cfb249750910d to your computer and use it in GitHub Desktop.
Terms aggregation filtered the length of terms
DELETE /filtered_aggs
PUT /filtered_aggs
PUT /filtered_aggs/example/1
{
"text" : "this is test doc"
}
PUT /filtered_aggs/example/2
{
"text" : "elasticsearch is fantastic open source"
}
GET /filtered_aggs/_search
GET /filtered_aggs/_search
{
"aggs": {
"term_count": {
"terms": {
"field": "text",
"script": "_value.length() > 2 ? _value : ''",
"size": 10
}
}
}
}
## output sample
{
"took": 13,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "filtered_aggs",
"_type": "example",
"_id": "1",
"_score": 1,
"_source": {
"text": "this is test doc"
}
},
{
"_index": "filtered_aggs",
"_type": "example",
"_id": "2",
"_score": 1,
"_source": {
"text": "elasticsearch is fantastic open source"
}
}
]
},
"aggregations": {
"term_count": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "is",
"doc_count": 2
},
{
"key": "doc",
"doc_count": 1
},
{
"key": "elasticsearch",
"doc_count": 1
},
{
"key": "fantastic",
"doc_count": 1
},
{
"key": "open",
"doc_count": 1
},
{
"key": "source",
"doc_count": 1
},
{
"key": "test",
"doc_count": 1
},
{
"key": "this",
"doc_count": 1
}
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment