1.GET store_index/_search
{
"query": {
"bool": {
"filter": [
{
"term": {
"isActive": 1
}
},
{
"has_child": {
"type": "store-order-stats",
"query": {
"bool": {
"filter": [
{
"range": {
"payDate": {
"gte": 20201101,
"lte": 20201130
}
}
},
{
"range": {
"orderCount": {
"gt": 0
}
}
}
]
}
}
}
}
]
}
},
"size": 0,
"aggs":{
"storeIds":{
"scripted_metric": {
"init_script": "state.transactions = []",
"map_script": "state.transactions.add(doc.storeId.value)",
"combine_script": "state.transactions",
"reduce_script": "ArrayList array=new ArrayList();for (i in states) { for(j in i){array.add(j);} } return array"
}
}
}
}
2.哈希2个值
public function getTeambuyOrderSumScript($num = 200, $dataDim=1 ,$type=1){ $field = 'realTotalCost'; if($dataDim != 1) $field = 'teamMoney'; if($type == 1){ $t = 'int t=0;'; $tAdd = 't++;'; $return = 't'; }elseif($type == 2){ $t = "String t='';"; $tAdd = "t=t+','+i;"; $return = 't'; }else{ $t = "int t=0;int money;"; $tAdd = "{t++;money+=m.get(i)}"; $return = "t+','+money"; } $sumscript = ['scripted_metric'=>[]]; $sumscript['scripted_metric']['init_script'] = 'state.m = new HashMap();'; $sumscript['scripted_metric']['map_script'] = 'String d = String.valueOf(doc.drugstoreBranchId.value);double a = state.m.get(d) == null ? 0 : state.m.get(d);a+=doc.'.$field.'.value;state.m.put(d,a);'; $sumscript['scripted_metric']['combine_script'] = 'return state.m;'; $sumscript['scripted_metric']['reduce_script'] = $t.'Map m = new HashMap();for (i in states) {if(i!=null)for (j in i.keySet()) {double a = m.get(j)==null?0:m.get(j);double b = i.get(j);a+=b;m.put(j,a);}}for(i in m.keySet()){if(m.get(i)>='.$num.')'.$tAdd.'} return '.$return.';'; return $sumscript; }