0

我正在尝试获取sum字段priceprice_department.

映射是:

                'completed_order' => [
                    'properties' => [
                        'driver_id'        => [
                            'type'  => 'integer',
                            'index' => 'not_analyzed',
                        ],
                        'order_id'         => [
                            'type'  => 'integer',
                            'index' => 'not_analyzed',
                        ],
                        'price'            => [
                            'type'  => 'float',
                            'index' => 'not_analyzed',
                        ],
                        'price_department' => [
                            'type'  => 'float',
                            'index' => 'not_analyzed',
                        ],
                    ],
                ],

问题是总和price_department是一个整数值。我还试图获取该领域的统计数据。结果是:

...'_source' => 
  array (size=6)
    'driver_id' => int 4469
    'price' => float 5.99
    'order_id' => int 2200676
    'price_department' => float 5.99...

...'total_price' => 
  array (size=1)
    'value' => float 5.99
'department_price' => 
  array (size=1)
    'value' => float 5
'department_price_stats' => 
  array (size=5)
    'count' => int 1
    'min' => float 5
    'max' => float 5
    'avg' => float 5
    'sum' => float 5

aggsbody:_

'aggs'  => [
  'drivers' => [
    'terms' => ['field' => 'driver_id','size' => 0,],
    'aggs'  => [
      'total_price' => ['sum' => ['field' => 'price',],],
      'department_price' => ['sum' => ['field' => 'price_department',],],
      'department_price_stats' => ['stats' => ['field' => 'price_department',],],
     ],
   ],
 ],

如您所见,sumofprice看起来正确,但sumand statsofprice_department被四舍五入并以整数形式返回。

4

1 回答 1

0

我有同样的问题。

结果我的映射设置为short,需要使用float、double或half_float来获得float返回而不是整数返回。

检查你的映射!!

于 2017-03-24T03:38:53.140 回答