各キャンペーンの表示回数とクリック数(campaign_idによる)を取得するには、次の用語の集計を使用します。
"aggregations": {
"campaigns": {
"terms": {
"field": "campaign_id",
"size": 10,
"order": {
"_term": "asc"
}
},
"aggregations": {
"actions": {
"terms": {
"field": "action",
"size": 10
}
}
}
}}
これは私が得る応答です:
"aggregations": {
"campaigns": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "someId",
"doc_count": 12,
"actions": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "click",
"doc_count": 3
},
{
"key": "view",
"doc_count": 9
}
]
}
}
]
}
}
編集: これが文書の例です(それに関連する部分だけ..):
{
"_index": "action",
"_type": "click",
"_id": "AVI2XOTl8otXlszOjypT",
"_score": 1,
"_source": {
"ip": "127.0.0.1",
"timestamp": "2016-01-12T15:03:23.622743524Z",
"action": "click",
"campaign_id": "IypmiroC"
}}
各キャンペーンのコンバージョン率(クリック数/ビュー数)を取得できるようにする必要があります。コンバージョン率で並べ替える必要があるため、クライアント側で行うことはできません。
どんな助けでも大歓迎です。
回答:
回答№1は4これは様々な使用が必要になります aggregations
そして ES 2.x
。まず、私はすべてのユニークなcampaign_idを取得しています 用語集。それから私は フィルタリング 〜と actions
そして、 カウント その特定のアクションを持つドキュメントの。それならあなたは使う必要があります pipeline aggregation
で紹介された ES 2.0
主に バケットスクリプト集計 比率を取るために。これはそれがどのように見えるかです。
{
"size": 0,
"aggs": {
"unique_campaign": {
"terms": {
"field": "campaign_id",
"size": 10
},
"aggs": {
"click_bucket": {
"filter": {
"term": {
"action": "click"
}
},
"aggs": {
"click_count": {
"value_count": {
"field": "action"
}
}
}
},
"view_bucket": {
"filter": {
"term": {
"action": "view"
}
},
"aggs": {
"view_count": {
"value_count": {
"field": "action"
}
}
}
},
"conversion_ratio": {
"bucket_script": {
"buckets_path": {
"total_clicks": "click_bucket>click_count",
"total_views": "view_bucket>view_count"
},
"script": "total_clicks/total_views"
}
}
}
}
}
}
また、持っている必要があります not_analyzed
のマッピング action
として クリック 一致しない クリック.
お役に立てれば!!