From 78eff1f540272b65617d331a50df2a313df07c57 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Tue, 15 Sep 2020 17:52:06 -0400 Subject: [PATCH] Fix docvalue fetch for scaled floats In #61995 I moved the `docvalue_field` fetch code into a place where I could share it with the fancy new `fields` fetch API. Specifically, runtime fields can use it all that doc values code now. But I broke `scaled_floats` by switching them how they are fetched from `double` to `string`. This adds the override you need to switch them back. --- .../index/mapper/ScaledFloatFieldMapper.java | 20 +++++++++++++++++++ .../test/scaled_float/10_basic.yml | 12 +++++++++++ .../test/search/10_source_filtering.yml | 12 ++++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java index 664a3a905250..71b81f2dfefe 100644 --- a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java +++ b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java @@ -544,5 +544,25 @@ public int docValueCount() { } } + @Override + public DocValueFetcher.Leaf getLeafValueFetcher(DocValueFormat format) { + SortedNumericDoubleValues values = getDoubleValues(); + return new DocValueFetcher.Leaf() { + @Override + public boolean advanceExact(int docId) throws IOException { + return values.advanceExact(docId); + } + + @Override + public int docValueCount() throws IOException { + return values.docValueCount(); + } + + @Override + public Object nextValue() throws IOException { + return format.format(values.nextValue()); + } + }; + } } } diff --git a/modules/mapper-extras/src/yamlRestTest/resources/rest-api-spec/test/scaled_float/10_basic.yml b/modules/mapper-extras/src/yamlRestTest/resources/rest-api-spec/test/scaled_float/10_basic.yml index 800944e3a5d6..f68385d25114 100644 --- a/modules/mapper-extras/src/yamlRestTest/resources/rest-api-spec/test/scaled_float/10_basic.yml +++ b/modules/mapper-extras/src/yamlRestTest/resources/rest-api-spec/test/scaled_float/10_basic.yml @@ -122,3 +122,15 @@ setup: - match: { hits.total.value: 4 } - match: { hits.hits.0._id: "3" } - match: { hits.hits.0.sort.0: -2 } + +--- +"docvalue_fields": + + - do: + search: + body: + docvalue_fields: [ "number" ] + sort: + number: + order: asc + - match: { hits.hits.0.fields.number: [-2.1] } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search/10_source_filtering.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/search/10_source_filtering.yml index df6664141c3b..58b1fadb1c14 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search/10_source_filtering.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search/10_source_filtering.yml @@ -14,7 +14,7 @@ setup: index: index: test_1 id: 1 - body: { "include": { "field1": "v1", "field2": "v2" }, "count": 1, "bigint": 72057594037927936 } + body: { "include": { "field1": "v1", "field2": "v2" }, "count": 1, "bigint": 72057594037927936, d: 3.14 } - do: indices.refresh: {} @@ -175,3 +175,13 @@ setup: - field: "count" format: "#.0" - match: { hits.hits.0.fields.count: ["1.0"] } + +--- +"docvalue_fields - double": + + - do: + search: + body: + docvalue_fields: [ "d" ] + - match: { hits.hits.0.fields.d: [3.140000104904175] } +