Created
January 21, 2015 07:17
-
-
Save johtani/9687fb3cfb249750910d to your computer and use it in GitHub Desktop.
Terms aggregation filtered the length of terms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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