Elasticsearch sum返回float字段的舍入整数值

时间:2017-01-24 11:16:08

标签: elasticsearch elasticsearch-aggregation

我想获得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

aggs的{​​{1}}是:

body

正如您所看到的,'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',],], ], ], ], 的{​​{1}}看起来是正确的,但sumprice的{​​{1}}被舍入并以整数形式返回。

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。

原来我将我的映射设置为short,需要使用float,double或half_float来获取float返回而不是整数返回。

检查你的映射!!