From 75d564b6b7172325fa4591a37e05c26e8efb7818 Mon Sep 17 00:00:00 2001 From: Yaliang <49084640+ylwu-amzn@users.noreply.github.com> Date: Tue, 3 Nov 2020 19:34:34 -0800 Subject: [PATCH] filter out empty value for entity features (#306) --- .../ad/feature/SearchFeatureDao.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/feature/SearchFeatureDao.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/feature/SearchFeatureDao.java index 80d795c9..81dd8aba 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/feature/SearchFeatureDao.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/feature/SearchFeatureDao.java @@ -793,9 +793,11 @@ public void getFeaturesByEntities( .stream() .filter(agg -> AGG_NAME_TERM.equals(agg.getName())) .flatMap(agg -> ((Terms) agg).getBuckets().stream()) - .collect( - Collectors.toMap(Terms.Bucket::getKeyAsString, bucket -> parseBucket(bucket, detector.getEnabledFeatureIds()).get()) - ); + .collect(Collectors.toMap(Terms.Bucket::getKeyAsString, bucket -> parseBucket(bucket, detector.getEnabledFeatureIds()))) + .entrySet() + .stream() + .filter(entry -> entry.getValue().isPresent()) + .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().get())); listener.onResponse(results); }, listener::onFailure);