0

ここに私のインデックスの構造:

[
    {
        "Id":"1",
        "Path":"/Series/Current/SerieA/foo/foo",
        "PlayCount":100
    },
    {
        "Id":"2",
        "Path":"/Series/Current/SerieA/bar/foo",
        "PlayCount":1000
    },
    {
        "Id":"3",
        "Path":"/Series/Current/SerieA/bar/bar",
        "PlayCount":50
    },
    {
        "Id":"4",
        "Path":"/Series/Current/SerieB/bla/bla",
        "PlayCount":300
    },
    {
        "Id":"5",
        "Path":"/Series/Current/SerieB/goo/boo",
        "PlayCount":200
    },
    {
        "Id":"6",
        "Path":"/Series/Current/SerieC/foo/zoo",
        "PlayCount":100
    }
]

次のような各シリーズの「PlayCount」の合計をもたらす集計を実行したいと思います。

[
    {
        "key":"serieA",
        "TotalPlayCount":1150
    },
    {
        "key":"serieB",
        "TotalPlayCount":500
    },
    {
        "key":"serieC",
        "TotalPlayCount":100
    }
]

これは私がやろうとする方法ですが、これは適切な方法ではないため、明らかにクエリは失敗します:

{
    "size": 0,
    "query":{
        "filtered":{
            "query":{
                "regexp":{
                    "Path":"/Series/Current/.*"
                }
            }
        }
    },
    "aggs":{
        "play_count_for_current_series":{
            "terms": {
                "field": "Path", 
                "regexp": "/Series/Current/([^/]+)"
            },
            "aggs":{
                "Total_play": { "sum": { "field": "PlayCount" } }
            }
        }
    }
}

それを行う方法はありますか?

4

1 に答える 1