我想计算分析的每个令牌。
首先,我尝试了以下代码:
映射:
{
"docs": {
"mappings": {
"doc": {
"dynamic": "false",
"properties": {
"text": {
"type": "string",
"analyzer": "kuromoji"
}
}
}
}
}
}
查询:
{
"query": {
"match_all": {}
},
"aggs": {
"word-count": {
"terms": {
"field": "text",
"size": "1000"
}
}
},
"size": 0
}
插入数据后查询索引,得到以下结果:
{
"took": 41
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 10000,
"max_score": 0,
"hits": []
},
"aggregations": {
"word-count": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 36634,
"buckets": [
{
"key": "はい",
"doc_count": 4734
},
{
"key": "いただく",
"doc_count": 2440
},
...
]
}
}
}
不幸的是,术语聚合只提供一个 doc_count。这不是字数。_index['text']['TERM'].df()
所以,我认为使用and获得近似字数的方法_index['text']['TERM'].ttf()
。
也许近似的字数是以下等式:
WordCount = doc_count['TERM'] / _index['text']['TERM'].df() * _index['text']['TERM'].ttf()
“期限”是存储桶中的关键。我试图编写一个脚本化的度量聚合,但我不知道如何获取存储桶中的键。
{
"query": {
"match_all": {}
},
"aggs": {
"doc-count": {
"terms": {
"field": "text",
"size": "1000"
}
},
"aggs": {
"word-count": {
"scripted_metric": {
// ???
}
}
}
},
"size": 0
}
如何获取存储桶中的密钥?如果不可能,我怎样才能得到分析的字数?