Perl reads the number as a string, so instead mapped the field as a long specifically. Also, the value returned in JSON is an integer, not a float
@@ -1,6 +1,14 @@
---
-"Expressions scripting test":
-
+setup:
+ - do:
+ indices.create:
+ index: test123
+ body:
+ mappings:
+ test:
+ properties:
+ age:
+ type: long
- do:
index:
index: test123
@@ -11,5 +19,9 @@
indices.refresh: {}
+---
+"Expressions scripting test":
+
- do: { search: { body: { script_fields : { my_field : { lang: expression, script: 'doc["age"].value' } } } } }
- - match: { hits.hits.0.fields.my_field: [ 23.0 ] }
+ - match: { hits.hits.0.fields.my_field: [ 23 ] }