Skip to content

Commit

Permalink
Fix docvalue fetch for scaled floats
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nik9000 committed Sep 15, 2020
1 parent 1f03fdc commit 78eff1f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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] }
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}

Expand Down Expand Up @@ -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] }

0 comments on commit 78eff1f

Please sign in to comment.