当前位置: 动力学知识库 > 问答 > 编程问答 >

Word Cloud in Elasticsearch 5

问题描述:

I am able to get word cloud using old elasticsearch version using term aggregations. I want to get word cloud from post content in es5 and I am using below query.

"aggs": {

"tagcloud": {

"terms": {

"field": "content.raw",

"size": 10

}

}

}

I did mapping like this

"content": {

"type": "text",

"fields": {

"raw": {

"type": "keyword"

}

}

}

But the result is not coming as a word cloud as expected. It is grouping similar posts (whole post) and giving as a list given belown

"buckets": [

{

"key" : "This car is awesome.",

"doc_count" : 199

},

..

..

How to do this?

网友答案:

The type keyword does pretty much the same as string with not_analyzed index mode. The whole string is indexed. And you can search only by exact value. In your case, I think, you need to use a field that is analyzed and tokenized, such as content field. However you need to make sure that the field's option fielddata is set to true. Otherwise server returns exception. Therefore your mapping should look like

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

and aggregation

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

As the result you should see something that looks like (it depends on what analyzer you choose)

"buckets": [
{
    "key" : "this",
    "doc_count" : 199
},
{
    "key" : "car",
    "doc_count" : 199
},
{
    "key" : "is",
    "doc_count" : 199
},
{
    "key" : "awesome",
    "doc_count" : 199
},
...
分享给朋友:
您可能感兴趣的文章:
随机阅读: