Fix scaled_float numeric type in aggregations (#22351)

`scaled_float` should be used as DOUBLE in aggregations but currently they are used as LONG.
This change fixes this issue and adds a simple it test for it.

Fixes #22350
This commit is contained in:
Jim Ferenczi 2016-12-27 09:23:22 +01:00 committed by GitHub
parent 3cb164b22e
commit e7444f7d77
3 changed files with 54 additions and 1 deletions

View File

@ -504,7 +504,10 @@ public class ScaledFloatFieldMapper extends FieldMapper {
@Override @Override
public NumericType getNumericType() { public NumericType getNumericType() {
return scaledFieldData.getNumericType(); /**
* {@link ScaledFloatLeafFieldData#getDoubleValues()} transforms the raw long values in `scaled` floats.
*/
return NumericType.DOUBLE;
} }
} }

View File

@ -182,6 +182,7 @@ public class ScaledFloatFieldTypeTests extends FieldTypeTestCase {
// single-valued // single-valued
ft.setName("scaled_float1"); ft.setName("scaled_float1");
IndexNumericFieldData fielddata = (IndexNumericFieldData) ft.fielddataBuilder().build(indexSettings, ft, null, null, null); IndexNumericFieldData fielddata = (IndexNumericFieldData) ft.fielddataBuilder().build(indexSettings, ft, null, null, null);
assertEquals(fielddata.getNumericType(), IndexNumericFieldData.NumericType.DOUBLE);
AtomicNumericFieldData leafFieldData = fielddata.load(reader.leaves().get(0)); AtomicNumericFieldData leafFieldData = fielddata.load(reader.leaves().get(0));
SortedNumericDoubleValues values = leafFieldData.getDoubleValues(); SortedNumericDoubleValues values = leafFieldData.getDoubleValues();
values.setDocument(0); values.setDocument(0);

View File

@ -18,6 +18,9 @@ setup:
type: long type: long
double: double:
type: double type: double
scaled_float:
type: scaled_float
scaling_factor: 100
date: date:
type: date type: date
@ -282,6 +285,52 @@ setup:
- match: { aggregations.double_terms.buckets.1.doc_count: 1 } - match: { aggregations.double_terms.buckets.1.doc_count: 1 }
---
"Scaled float test":
- do:
index:
index: test_1
type: test
id: 1
body: { "scaled_float": 9.99 }
- do:
index:
index: test_1
type: test
id: 2
body: { "scaled_float": 9.994 }
- do:
index:
index: test_1
type: test
id: 3
body: { "scaled_float": 8.99 }
- do:
indices.refresh: {}
- do:
search:
body: { "size" : 0, "aggs" : { "scaled_float_terms" : { "terms" : { "field" : "scaled_float" } } } }
- match: { hits.total: 3 }
- length: { aggregations.scaled_float_terms.buckets: 2 }
- match: { aggregations.scaled_float_terms.buckets.0.key: 9.99 }
- is_false: aggregations.scaled_float_terms.buckets.0.key_as_string
- match: { aggregations.scaled_float_terms.buckets.0.doc_count: 2 }
- match: { aggregations.scaled_float_terms.buckets.1.key: 8.99 }
- is_false: aggregations.scaled_float_terms.buckets.1.key_as_string
- match: { aggregations.scaled_float_terms.buckets.1.doc_count: 1 }
--- ---
"Date test": "Date test":
- do: - do: