From 93a28b0acfff5332e97616f53b5d52fe8b933306 Mon Sep 17 00:00:00 2001 From: srgclr Date: Tue, 24 Jan 2017 17:49:53 +0000 Subject: [PATCH] skip parentid if child document is an orphan #22770 --- .../search/fetch/subphase/ParentFieldSubFetchPhase.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/src/main/java/org/elasticsearch/search/fetch/subphase/ParentFieldSubFetchPhase.java b/core/src/main/java/org/elasticsearch/search/fetch/subphase/ParentFieldSubFetchPhase.java index cb8310975fc1f..5cd19096beb1d 100644 --- a/core/src/main/java/org/elasticsearch/search/fetch/subphase/ParentFieldSubFetchPhase.java +++ b/core/src/main/java/org/elasticsearch/search/fetch/subphase/ParentFieldSubFetchPhase.java @@ -63,6 +63,10 @@ public void hitExecute(SearchContext context, HitContext hitContext) { public static String getParentId(ParentFieldMapper fieldMapper, LeafReader reader, int docId) { try { SortedDocValues docValues = reader.getSortedDocValues(fieldMapper.name()); + if (docValues == null) { + // hit has no _parent field. + return null; + } BytesRef parentId = docValues.get(docId); return parentId.length > 0 ? parentId.utf8ToString() : null; } catch (IOException e) {