我正在尝试获取sum
字段price
和price_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',],],
],
],
],
如您所见,price
的sum
看起来是正确的,但price_department
的sum
和stats
是四舍五入并以整数形式返回的。
我也有同样的问题。
事实证明,我将映射设置为短,需要使用浮点数、双精度或half_float来获得浮点返回而不是整数返回。
检查您的映射!!