elasticsearch - Elasticsearch 聚合 Suggesters 的结果
问题描述
我是 Elasticsearch 的初学者。我想汇总 Completion Suggester 的结果。
有多个索引,并且在“标签”字段中添加了多个标签,如下所示。
文件
GET http://localhost:9200/index1/user-category1/1?pretty
{
"_index": "index1",
"_type": "user-category1",
"_id": "1",
"_version": 1,
"found": true,
"_source": {
"user_id": 1,
"tags": [
"Apple",
"Orange",
"Peach"
]
}
}
GET http://localhost:9200/index2/user-category2/2?pretty
{
"_index": "index2",
"_type": "user-category2",
"_id": "2",
"_version": 1,
"found": true,
"_source": {
"user_id": 2,
"tags": [
"Grape",
"Apple"
]
}
}
然后,我创建了这样的映射。
映射
"tags": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
},
"suggest": {
"type": "completion"
}
}
}
询问
POST http://localhost:9200/_all/_search?pretty
{
"_source": false,
"suggest": {
"tags_suggest": {
"prefix": "A",
"completion": {
"field": "tags.suggest"
}
}
}
}
结果
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 2,
"successful": 2,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 0,
"max_score": 0,
"hits": []
},
"suggest": {
"tags_suggest": [
{
"text": "A",
"offset": 0,
"length": 1,
"options": [
{
"text": "Apple",
"_index": "index1",
"_type": "user-category1",
"_id": "1",
"_score": 1
},
{
"text": "Apple",
"_index": "index2",
"_type": "user-category2",
"_id": "2",
"_score": 1
}
]
}
]
}
}
查询正确返回建议的结果,但是,问题是我无法获得“Apple”的总数如何获得如下结果?
"aggregations": {
"keywords": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Apple",
"doc_count": 2
}
]
}
}
我尝试了下面的查询,但它不起作用。
{
"_source": false,
"suggest": {
"tags_suggest": {
"prefix": "A",
"completion": {
"field": "tags.suggest"
}
}
},
"aggs": {
"tags": {
"terms": {
"field": "tags.keyword"
}
}
}
}
解决方案
推荐阅读
- ruby-on-rails - 在 Rails 中为 Wikimedia Maps 添加电子邮件到 HTTP 用户代理
- javascript - 当我在反应 js 中运行构建文件时,UI 出现放大
- c# - webApi OAuthAuthorizationServerProvider 我该如何编写注销
- python - Python 2.7 _ 添加到字符串会删除字符串?
- ruby - 从控制台读取输入后程序不继续
- python - 'AttributeError:模块'usbiss'在创建类实例时没有属性Aclass'
- wpf - DotTrace 没有明确的大量用户代码执行时间
- java - GWTP Presenter 和 View 保留旧值
- json - JSON代码beutify得到一个错误期望'STRING','NUMBER','NULL','TRUE','FALSE','{','[',得到'undefined'
- ios - iOS 上的 fft numpy 风格以非两个数据长度的幂加速