fix(lineage) Fix lineage source/dest filtering with explored per hop limit (#10879)

This commit is contained in:
Chris Collins 2024-07-12 10:59:57 -04:00 committed by GitHub
parent aa92a99130
commit d77d565ba9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -177,13 +177,18 @@ public class ESGraphQueryDAO {
sourceFilterQuery.minimumShouldMatch(1);
validEdges.stream()
.filter(pair -> RelationshipDirection.OUTGOING.equals(pair.getValue().getDirection()))
.forEach(pair -> sourceFilterQuery.should(getAggregationFilter(pair)));
.forEach(
pair ->
sourceFilterQuery.should(
getAggregationFilter(pair, RelationshipDirection.OUTGOING)));
BoolQueryBuilder destFilterQuery = QueryBuilders.boolQuery();
destFilterQuery.minimumShouldMatch(1);
validEdges.stream()
.filter(pair -> RelationshipDirection.INCOMING.equals(pair.getValue().getDirection()))
.forEach(pair -> destFilterQuery.should(getAggregationFilter(pair)));
.forEach(
pair ->
destFilterQuery.should(getAggregationFilter(pair, RelationshipDirection.INCOMING)));
FilterAggregationBuilder sourceRelationshipTypeFilters =
AggregationBuilders.filter(FILTER_BY_SOURCE_RELATIONSHIP, sourceFilterQuery);
@ -226,17 +231,28 @@ public class ESGraphQueryDAO {
}
}
private BoolQueryBuilder getAggregationFilter(Pair<String, EdgeInfo> pair) {
private BoolQueryBuilder getAggregationFilter(
Pair<String, EdgeInfo> pair, RelationshipDirection direction) {
BoolQueryBuilder subFilter = QueryBuilders.boolQuery();
TermQueryBuilder relationshipTypeTerm =
QueryBuilders.termQuery(RELATIONSHIP_TYPE, pair.getValue().getType());
QueryBuilders.termQuery(RELATIONSHIP_TYPE, pair.getValue().getType()).caseInsensitive(true);
subFilter.must(relationshipTypeTerm);
String sourceType;
String destinationType;
if (direction.equals(RelationshipDirection.OUTGOING)) {
sourceType = pair.getKey();
destinationType = pair.getValue().getOpposingEntityType();
} else {
sourceType = pair.getValue().getOpposingEntityType();
destinationType = pair.getKey();
}
TermQueryBuilder sourceTypeTerm =
QueryBuilders.termQuery(SOURCE + ".entityType", pair.getKey());
QueryBuilders.termQuery(SOURCE + ".entityType", sourceType).caseInsensitive(true);
subFilter.must(sourceTypeTerm);
TermQueryBuilder destinationTypeTerm =
QueryBuilders.termQuery(
DESTINATION + ".entityType", pair.getValue().getOpposingEntityType());
QueryBuilders.termQuery(DESTINATION + ".entityType", destinationType).caseInsensitive(true);
subFilter.must(destinationTypeTerm);
return subFilter;
}