2016-09-22 9 views
0

ESクエリーから不適切な集計カウントが取得されています。私はES文書の基数から理解していますが、用語の集計は正確ではありませんが、私が得たのはあまり差がありません。私のインデックスの弾性検索集計ミスマッチ

マッピングは、私が使用して、ソースによって各デバイスの各ソースと独自の無セッションのためのセッションのユニークなノーを取得していますクエリ以下から

{ 
     "dynamic_templates": [{ 
      "template_action": { 
       "mapping": { 
        "type": "string", 
        "index": "not_analyzed" 
       }, 
       "match": "*", 
       "match_mapping_type": "*" 
      } 
     }], 
     "_parent": { 
      "type": "users" 
     }, 
     "date_detection": False, 
     "properties": { 
      "traits": { 
       "type": "object" 
      }, 
      "cl_utm_params": { 
       "type": "object" 
      }, 
      "cl_other_params": { 
       "type": "object" 
      }, 
      "cl_triggered_ts": { 
       "type": "date" 
      } 
     } 
    } 

サンプル文書

{ 
     "client_id": "cl58vivh8w7t", 
     "user_id": "CL.1122029143.1904488380.1218174474.2049762488", 
     "session_id": "CL.1886305621.906039613", 
     "source": "Google", 
     "action": "pageview", 
     "cl_triggered_ts": "2016-09-09T00:13:33.818Z", 
     "browser": "Microsoft Edge 13", 
     "platform": "Windows 10", 
     "screen_size": "1920 x 1080", 
     "device": "Desktop", 
     "ip_address": "98.236.246.165", 
     "country": "United States", 
     "city": "Weirton", 
     "postal_code": "26062", 
     "location": "40.4224, -80.5739", 
     "timezone": "America/New_York", 
     "state": "West Virginia", 
     "continent": "North America", 
     "isp": "Comcast Cable", 
     "browser_language": "", 
     "traits": {}, 
     "cl_utm_params": {}, 
     "cl_other_params": {} 
    } 

ですバケットとメトリックの集計

{ 
    "query": { 
    "bool": { 
     "must": [ 
      {"match": {"client_id": "cl58vivh8w7t"}} 
     ] 
    } 
    }, 
    "aggs": { 
    "top_source": { 
     "terms": { 
      "field": "source" 
     }, 
     "aggs": { 
      "total_unique_sessions": {"cardinality": {"field": "session_id"}}, 
      "per_device": { 
       "terms": {"field": "device"}, 
       "aggs": {"device_session": {"cardinality": {"field": "session_id"}}} 
       } 
      } 
     } 
    }, 
    "size": 0 
} 

参考までに、下のバケツ。これから各デバイスのセッション値の合計はtotal_unique_sessions値と等しくなければなりません。

質問や計算に問題があると思われますか?

{ 
     "key": "www.google.com", 
     "doc_count": 68947, 
     "per_device": { 
     "doc_count_error_upper_bound": 0, 
     "sum_other_doc_count": 0, 
     "buckets": [ 
      { 
      "key": "Desktop", 
      "doc_count": 49254, 
      "device_session": { 
       "value": 2413 
      } 
      }, 
      { 
      "key": "Mobile", 
      "doc_count": 16317, 
      "device_session": { 
       "value": 3222 
      } 
      }, 
      { 
      "key": "Tablet", 
      "doc_count": 3343, 
      "device_session": { 
       "value": 636 
      } 
      }, 
      { 
      "key": "TV", 
      "doc_count": 33, 
      "device_session": { 
       "value": 9 
      } 
      } 
     ] 
     }, 
     "total_unique_sessions": { 
     "value": 9058 
     } 
    } 

答えて

0

あなたは一致クエリを使用しています。

通常、集計の用語クエリです。私はこの問題を引き起こしていると思います。

{ 
    "query": { 
    "bool": { 
     "must": [ 
      {"term": {"client_id": "cl58vivh8w7t"}} 
     ] 
    } 
    }, 
    "aggs": { 
    "top_source": { 
     "terms": { 
      "field": "source" 
     }, 
     "aggs": { 
      "total_unique_sessions": {"cardinality": {"field": "session_id"}}, 
      "per_device": { 
       "terms": {"field": "device"}, 
       "aggs": {"device_session": {"cardinality": {"field": "session_id"}}} 
       } 
      } 
     } 
    }, 
    "size": 0 
} 
+0

はええ、迅速に結果を得るために分析分野の試合以上の用語を使用することが良いのですが、ここでのclient_idがnot_analysedされるように、このクエリに意味がありません。どちらの結果も同じ数字です。 – shivg