Skip to content

Commit

Permalink
Fix Term Vectors with artificial docs and keyword fields
Browse files Browse the repository at this point in the history
Previously, Term Vectors API was returning empty results for
artificial documents with keyword fields. Checking only for `string()`
on `IndexableField` is not enough, since for `KeywordFieldType`
`binaryValue()` must be used instead.

Fixes elastic#53494
  • Loading branch information
matriv committed Mar 12, 2020
1 parent 5ccb3b6 commit fb058c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,12 @@ public IndexableField[] getFields(String name) {
public final String[] getValues(String name) {
List<String> result = new ArrayList<>();
for (IndexableField field : fields) {
if (field.name().equals(name) && field.stringValue() != null) {
result.add(field.stringValue());
if (field.name().equals(name)) {
if (field.stringValue() != null) {
result.add(field.stringValue());
} else if (field.binaryValue() != null) { // KeywordFieldType
result.add(field.binaryValue().utf8ToString());
}
}
}
return result.toArray(new String[result.size()]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ public void testDefaults() throws Exception {
fieldType = fields[1].fieldType();
assertThat(fieldType.indexOptions(), equalTo(IndexOptions.NONE));
assertEquals(DocValuesType.SORTED_SET, fieldType.docValuesType());

assertArrayEquals(new String[] { "1234", "1234" }, doc.rootDoc().getValues("field")); // used for TermVectors
}

public void testIgnoreAbove() throws IOException {
Expand Down

0 comments on commit fb058c6

Please sign in to comment.