弹性搜索总和返回浮点数字段的舍入整数值



我正在尝试获取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

body aggs是:

'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',],],
     ],
   ],
 ],

如您所见,pricesum看起来是正确的,但price_departmentsumstats是四舍五入并以整数形式返回的。

我也有同样的问题。

事实证明,我将映射设置为短,需要使用浮点数、双精度或half_float来获得浮点返回而不是整数返回。

检查您的映射!!

最新更新