others - 在关键字查询中,ElasticSearch聚合 sum_other_doc_count?

我将这些显示给用户:


first (150)
second (122)
third(111)
...
other(19)

,然后用户可以通过选择一个关键字来过滤他们的结果,我使用他们选择的关键字来应用TermFilter ,可以正常工作。

然而,有没有一种方法可以创建表示"其它"(即除前10名外的所有关键字)的过滤器?

时间:

我创建了一个索引并添加了一些随机的拉丁文文本:


PUT /test_index
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
 }
}

POST /test_index/_bulk
{"index":{"_index":"test_index","_type":"doc"}}
{"text":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec rhoncus dictum ligula, quis volutpat diam fringilla ut."}
{"index":{"_index":"test_index","_type":"doc"}}
{"text":"Nulla ac gravida ipsum. Pellentesque placerat mattis pharetra. Praesent sapien lorem, auctor in imperdiet vel, lacinia vel diam."}
{"index":{"_index":"test_index","_type":"doc"}}
{"text":"Mauris a risus ut eros posuere rutrum. Nunc scelerisque diam ex, consequat mollis sem facilisis in."}
{"index":{"_index":"test_index","_type":"doc"}}
{"text":"Maecenas lacinia sollicitudin ultricies. Aenean id eleifend sapien. In et justo accumsan, cursus mi vel, consectetur augue. Nullam in quam ac magna iaculis finibus quis ut risus."}
{"index":{"_index":"test_index","_type":"doc"}}
{"text":"Donec dolor eros, rhoncus ultricies quam et, dapibus egestas libero."}

然后获得前5个词:


POST /test_index/_search?search_type=count
{
"aggs": {
"top_terms":{
"terms":{
"field":"text",
"size": 5
 }
 }
 }
}
...
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
 },
"hits": {
"total": 5,
"max_score": 0,
"hits": []
 },
"aggregations": {
"top_terms": {
"buckets": [
 {
"key":"diam",
"doc_count": 3
 },
 {
"key":"in",
"doc_count": 3
 },
 {
"key":"ut",
"doc_count": 3
 },
 {
"key":"ac",
"doc_count": 2
 },
 {
"key":"consectetur",
"doc_count": 2
 }
 ]
 }
 }
}

然后,我可以构造一个过滤器,使我返回没有前5个术语的文档,例如:


POST /test_index/_search
{
"query": {
"constant_score": {
"filter": {
"not": {
"filter": {
"terms": {
"text": [
"diam",
"in",
"ut",
"ac",
"consectetur"
 ]
 }
 }
 }
 },
"boost": 1.2
 }
 }
}
...
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
 },
"hits": {
"total": 1,
"max_score": 1,
"hits": [
 {
"_index":"test_index",
"_type":"doc",
"_id":"4uoLr70rRXulHHc7N3Ujmw",
"_score": 1,
"_source": {
"text":"Donec dolor eros, rhoncus ultricies quam et, dapibus egestas libero."
 }
 }
 ]
 }
}

我知道,这并不能真正回答你的问题,但是也许会给你一些提示。

...