Skip to content

Commit 78eff1f

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 1f03fdc commit 78eff1f

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
@@ -544,5 +544,25 @@ public int docValueCount() {
544544
}
545545
}
546546

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

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

@@ -175,3 +175,13 @@ setup:
175175
- field: "count"
176176
format: "#.0"
177177
- match: { hits.hits.0.fields.count: ["1.0"] }
178+
179+
---
180+
"docvalue_fields - double":
181+
182+
- do:
183+
search:
184+
body:
185+
docvalue_fields: [ "d" ]
186+
- match: { hits.hits.0.fields.d: [3.140000104904175] }
187+

0 commit comments

Comments
 (0)