diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java index 5f80520aadf..44f32737026 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/highlight/HighlightPhase.java @@ -169,9 +169,9 @@ public class HighlightPhase implements SearchHitPhase { } }); } - String[] fragments; + String[] fragments = null; // number_of_fragments is set to 0 but we have a multivalued field - if (field.numberOfFragments() == 0 && textsToHighlight.size() > 1) { + if (field.numberOfFragments() == 0 && textsToHighlight.size() > 1 && fragsList.size() > 0) { fragments = new String[1]; for (int i = 0; i < fragsList.size(); i++) { fragments[0] = (fragments[0] != null ? (fragments[0] + " ") : "") + fragsList.get(i).toString(); @@ -185,7 +185,7 @@ public class HighlightPhase implements SearchHitPhase { } } - if (fragments.length > 0) { + if (fragments != null && fragments.length > 0) { HighlightField highlightField = new HighlightField(field.field(), fragments); highlightFields.put(highlightField.name(), highlightField); }