diff --git a/src/main/java/org/elasticsearch/action/termvectors/TermVectorsWriter.java b/src/main/java/org/elasticsearch/action/termvectors/TermVectorsWriter.java index 21b990ed2fd..53cdd35bc09 100644 --- a/src/main/java/org/elasticsearch/action/termvectors/TermVectorsWriter.java +++ b/src/main/java/org/elasticsearch/action/termvectors/TermVectorsWriter.java @@ -104,9 +104,14 @@ final class TermVectorsWriter { if (flags.contains(Flag.TermStatistics)) { // get the doc frequency if (dfs != null) { - writeTermStatistics(dfs.termStatistics().get(term)); + final TermStatistics statistics = dfs.termStatistics().get(term); + writeTermStatistics(statistics == null ? new TermStatistics(termBytesRef, 0, 0) : statistics); } else { - writeTermStatistics(topLevelIterator); + if (foundTerm) { + writeTermStatistics(topLevelIterator); + } else { + writeTermStatistics(new TermStatistics(termBytesRef, 0, 0)); + } } } if (useDocsAndPos) { diff --git a/src/test/java/org/elasticsearch/action/termvectors/GetTermVectorsTests.java b/src/test/java/org/elasticsearch/action/termvectors/GetTermVectorsTests.java index 752a52d94ae..d99d03ec0b4 100644 --- a/src/test/java/org/elasticsearch/action/termvectors/GetTermVectorsTests.java +++ b/src/test/java/org/elasticsearch/action/termvectors/GetTermVectorsTests.java @@ -875,7 +875,7 @@ public class GetTermVectorsTests extends AbstractTermVectorsTests { checkBrownFoxTermVector(resp.getFields(), "field1", false); } - @Test @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/10660") + @Test public void testArtificialNonExistingField() throws Exception { // setup indices ImmutableSettings.Builder settings = settingsBuilder()