2016-11-14 12 views
0

私はElasticSearchインデックスを持っています。ここでは、テレフォニートランザクション(SMS、MMS、Callsなど)とそれに関連するコストが格納されています。String配列による弾性検索集約

これらのドキュメントのキーは、MSISDN(MSISDN =電話番号)です。私のアプリでは、ユーザーのグループがいることを知っています。各ユーザーは1つ以上のMSISDNを持つことができます。ここで

は、文書のこの種のマッピングです:

"mappings" : { 
     "cdr" : { 
     "properties" : { 
      "callDatetime" : { 
      "type" : "long" 
      }, 
      "callSource" : { 
      "type" : "string" 
      }, 
      "callType" : { 
      "type" : "string" 
      }, 
      "callZone" : { 
      "type" : "string" 
      }, 
      "calledNumber" : { 
      "type" : "string" 
      }, 
      "companyKey" : { 
      "type" : "string" 
      }, 
      "consumption" : { 
      "properties" : { 
       "data" : { 
       "type" : "long" 
       }, 
       "voice" : { 
       "type" : "long" 
       } 
      } 
      }, 
      "cost" : { 
      "type" : "double" 
      }, 
      "country" : { 
      "type" : "string" 
      }, 
      "included" : { 
      "type" : "boolean" 
      }, 
      "msisdn" : { 
      "type" : "string" 
      }, 
      "network" : { 
      "type" : "string" 
      } 
     } 
     } 
    } 

私の目標と問題:

私の目標は、でCALLTYPEによってコストを取得するクエリを作成することですグループ。しかし、グループはElasticSearchには表示されません。私のPostgreSQLデータベースでのみ表示されます。

既存のグループごとにすべてのMSISDNを取得し、各グループ内のすべてのMSISDNを含むString Arrayのリストのようなものを取得するメソッドを作成します。

のは、私のようなものがあるとしましょう:今すぐ

"msisdn_by_group" : [ 
    { 
     "group1" : ["01111111111", "02222222222", "033333333333", "044444444444"] 
    }, 
    { 
     "group2" : ["05555555555","06666666666"] 
    } 
] 

を、私はElasticsearchクエリを生成するためにこれを使用します。私は集計、コストの合計、異なるバケットのすべてのそれらの用語のためにしたいと思うし、再度コールタイプでそれを分割します。 (積重ね棒グラフを作成する)。

私はいくつかのことを試しましたが、それを機能させることはできませんでした(ヒストグラム、バケット、用語と合計は主に私が使っているキーワードでした)。

ここで誰かが順序で私を助けて、と私はこれを達成するために使用できるキーワードができれば、それは素晴らしい:)だろうおかげ

EDIT:ここに が私の最後の試みです: QUERY:

{ 
    "aggs" : { 
     "cost_histogram": { 
      "terms": { 
       "field": "callType" 
      }, 
      "aggs": { 
       "cost_histogram_sum" : { 
        "sum": { 
         "field": "cost" 
        } 
       } 
      } 
     } 
    } 
} 

私が期待される結果を行くが、私は基準としてMSISDNの配列を渡す方法がわからないとして、それは、「グループ」スプリットを行方不明:

結果:

"aggregations": { 
    "cost_histogram": { 
     "doc_count_error_upper_bound": 0, 
     "sum_other_doc_count": 0, 
     "buckets": [ 
     { 
      "key": "data", 
      "doc_count": 5925, 
      "cost_histogram_sum": { 
      "value": 0 
      } 
     }, 
     { 
      "key": "sms_mms", 
      "doc_count": 5804, 
      "cost_histogram_sum": { 
      "value": 91.76999999999995 
      } 
     }, 
     { 
      "key": "voice", 
      "doc_count": 5299, 
      "cost_histogram_sum": { 
      "value": 194.1196 
      } 
     }, 
     { 
      "key": "sms_mms_plus", 
      "doc_count": 35, 
      "cost_histogram_sum": { 
      "value": 7.2976 
      } 
     } 
     ] 
    } 
    } 
+1

あなたが現在持っている質問を表示して、何がまだ失われているか説明してください。 – Val

+0

@Valもちろん私はそれを忘れてしまった、私の悪い!私の編集を参照してください – Alex

+1

あなたの現在のものをラップする別の 'terms'集約が必要です。 – Val

答えて

0

[OK]を私は1つのクエリでこれを作る方法を見つけましたが、それはグループごとに繰り返されるので、それは気の長いクエリですが、私は何の一品を持っていません。私は "フィルター"アグリゲーターを使用しています。ここで

は、私は上記の私の質問に書いた配列に基づいて実施例である:

POSTのはlocalhost:9200/CDR/_search新しいバージョンへのサイズ= 0

{ 
    "query": { 
     "term" : { 
      "companyKey" : 1 
     } 
    }, 
    "aggs" : { 
     "group_1_split_cost": { 
      "filter": { 
       "bool": { 
        "should": [{ 
         "bool": { 
          "must": { 
           "match": { 
            "msisdn": "01111111111" 
           } 
          } 
         } 
        },{ 
         "bool": { 
          "must": { 
           "match": { 
            "msisdn": "02222222222" 
           } 
          } 
         } 
        },{ 
         "bool": { 
          "must": { 
           "match": { 
            "msisdn": "03333333333" 
           } 
          } 
         } 
        },{ 
         "bool": { 
          "must": { 
           "match": { 
            "msisdn": "04444444444" 
           } 
          } 
         } 
        }] 
       } 
      }, 
      "aggs": { 
       "cost_histogram": { 
        "terms": { 
         "field": "callType" 
        }, 
        "aggs": { 
         "cost_histogram_sum" : { 
          "sum": { 
           "field": "cost" 
          } 
         } 
        } 
       } 
      } 
     }, 
     "group_2_split_cost": { 
      "filter": { 
       "bool": { 
        "should": [{ 
         "bool": { 
          "must": { 
           "match": { 
            "msisdn": "05555555555" 
           } 
          } 
         } 
        },{ 
         "bool": { 
          "must": { 
           "match": { 
            "msisdn": "06666666666" 
           } 
          } 
         } 
        }] 
       } 
      }, 
      "aggs": { 
       "cost_histogram": { 
        "terms": { 
         "field": "callType" 
        }, 
        "aggs": { 
         "cost_histogram_sum" : { 
          "sum": { 
           "field": "cost" 
          } 
         } 
        } 
       } 
      } 
     } 
    } 
} 

のおかげ? Elasticsearchでは非常に深い集約をネストすることができますが、値の配列を "OR"演算子などに渡すことはできません。それらのクエリのサイズを減らすことができます。たとえそれがちょっと特別でニッチの場合に使用されるとしても、私のように。

関連する問題