Skip to content

Commit 37cd774

Browse files
committed
Fix docvalue fetch for scaled floats
In elastic#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.
1 parent 8855e23 commit 37cd774

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,5 +545,25 @@ public int docValueCount() {
545545
}
546546
}
547547

548+
@Override
549+
public DocValueFetcher.Leaf getLeafValueFetcher(DocValueFormat format) {
550+
SortedNumericDoubleValues values = getDoubleValues();
551+
return new DocValueFetcher.Leaf() {
552+
@Override
553+
public boolean advanceExact(int docId) throws IOException {
554+
return values.advanceExact(docId);
555+
}
556+
557+
@Override
558+
public int docValueCount() throws IOException {
559+
return values.docValueCount();
560+
}
561+
562+
@Override
563+
public Object nextValue() throws IOException {
564+
return format.format(values.nextValue());
565+
}
566+
};
567+
}
548568
}
549569
}

modules/mapper-extras/src/yamlRestTest/resources/rest-api-spec/test/scaled_float/10_basic.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,15 @@ setup:
122122
- match: { hits.total.value: 4 }
123123
- match: { hits.hits.0._id: "3" }
124124
- match: { hits.hits.0.sort.0: -2 }
125+
126+
---
127+
"docvalue_fields":
128+
129+
- do:
130+
search:
131+
body:
132+
docvalue_fields: [ "number" ]
133+
sort:
134+
number:
135+
order: asc
136+
- match: { hits.hits.0.fields.number: [-2.1] }

rest-api-spec/src/main/resources/rest-api-spec/test/search/10_source_filtering.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ setup:
1414
index:
1515
index: test_1
1616
id: 1
17-
body: { "include": { "field1": "v1", "field2": "v2" }, "count": 1, "bigint": 72057594037927936 }
17+
body: { "include": { "field1": "v1", "field2": "v2" }, "count": 1, "bigint": 72057594037927936, d: 3.14 }
1818
- do:
1919
indices.refresh: {}
2020

@@ -199,3 +199,13 @@ setup:
199199
- field: "count"
200200
format: "#.0"
201201
- match: { hits.hits.0.fields.count: ["1.0"] }
202+
203+
---
204+
"docvalue_fields - double":
205+
206+
- do:
207+
search:
208+
body:
209+
docvalue_fields: [ "d" ]
210+
- match: { hits.hits.0.fields.d: [3.140000104904175] }
211+

0 commit comments

Comments
 (0)