回顶领域的基础上嵌套的领域额略任

0

的问题

我是一个总ES初我不知道如果我想做的事甚至是可能的。 我有如下一个 viewer 索引用下面的映射:

"mappings": {
        "properties": {
            "id": {"type": "text"},
            "name": {"type": "text"},
            "location": {"type": "text"},
            "viewed_videos": { //array of all the videos a viewer saw and their view counts
                "type": "nested",
                "properties": {
                    "id": {"type": "text"},
                    "name": {"type": "text"},
                    "description": {"type": "text"},
                    "times_viewed": {"type": "long"},
                },
            },
        }
    }

我想弄清楚什么是最观看视频的位置。 所以我需要的方式总结 times_viewedviewed_video 在许多 viewers然后获得的最高X的一个特定位置。

这可能吗?

elasticsearch
2021-11-19 18:58:29
1

最好的答案

0

方案: 你将需要三个级别的聚集

  • 期聚集在位置场
  • 套期汇聚在观看视频的标识
  • 总和聚集在时间看

然而,期聚合不可能进行上文领域。 请注意,在文件 https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html:

默认情况下,不能运行一个方面聚集在一个文本的领域。 使用的关键词子领域,而不是。 或者,可以启用fielddata的文本区域创建桶领域的分析条款。 使fielddata可以大大增加存储器的使用。

这可能会帮助,以及: 一步深入使用这些聚合领域的文本类型的映射

一旦上述问题是固定的,这种查询该工作

GET viewer/_search
{
  "size": 0,
  "aggs": {
    "location": {
      "terms": {
        "field": "location"
      },
      "aggs": {
        "videos": {
          "nested": {
            "path": "viewed_videos"
          },
          "aggs": {
             "type": {
               "terms": {
                    "field": "viewed_videos.id"
                },
                "aggs": {
                  "count": {
                    "sum": {
                      "field": "viewed_videos.times_viewed"
                    }
                  },
                  "sorted_count": {
                    "bucket_sort": {
                      "sort": [
                        { "count": { "order": "desc" } } 
                      ],
                      "size": <X> // top X results                            
                    }
                  }
                } 
              }
            }
          }
       }
    }
  }
}
2021-11-20 08:11:05

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................