1

我可以使用术语聚合使用旧的弹性搜索版本来获取词云。我想从es5 中的帖子内容中获取词云,我正在使用以下查询。

"aggs": {
        "tagcloud": {
            "terms": {
                "field": "content.raw",
                "size": 10
            }
        }
    }

我做了这样的映射

"content": {
    "type": "text",
    "fields": {
        "raw": {
            "type": "keyword"
        }
    }
}

但结果并没有像预期的那样以文字云的形式出现。它正在对类似的帖子(整个帖子)进行分组,并作为下面给出的列表给出

"buckets": [
{
    "key" : "This car is awesome.",
    "doc_count" : 199
},
..
..

这个怎么做?

4

1 回答 1

2

该类型与索引模式keyword几乎相同。整个字符串被索引。而且您只能按确切值进行搜索。我认为,在您的情况下,您需要使用经过分析和标记化的字段,例如field. 但是,您需要确保该字段的选项设置为. 否则服务器返回异常。因此,您的映射应该看起来像stringnot_analyzedcontentfielddatatrue

"content": {
   "fielddata" : true,
   "type": "text"
}

和聚合

"aggs": {
    "tagcloud": {
        "terms": {
            "field": "content",
            "size": 10
        }
    }
}

结果,您应该会看到类似的东西(这取决于您选择的分析器)

"buckets": [
{
    "key" : "this",
    "doc_count" : 199
},
{
    "key" : "car",
    "doc_count" : 199
},
{
    "key" : "is",
    "doc_count" : 199
},
{
    "key" : "awesome",
    "doc_count" : 199
},
...
于 2017-01-18T14:43:22.177 回答