我不这么认为。不过,您可以使用terms 和not 过滤器将相关(但不完全相同)的内容组合在一起,这将返回所有未出现最重要术语的文档。为简单起见,我将使用前 5 个。
所以我创建了一个索引并添加了一些随机的拉丁文本:
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."
}
}
]
}
}
我知道这并不能真正回答你的问题,但也许它会给你一些想法。
这是我使用的代码(如果您使用的是 ES 1.4,则必须打开 CORS 才能在浏览器中使用该代码):
http://sense.qbox.io/gist/93b69375c5491f1b0458e2053a08e65006f34a1c