Skip to content

Commit

Permalink
fix(lineage) Fix lineage source/dest filtering with explored per hop …
Browse files Browse the repository at this point in the history
…limit
  • Loading branch information
chriscollins3456 committed Jul 9, 2024
1 parent d204d56 commit 6a17c71
Showing 1 changed file with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,18 @@ private SearchResponse executeGroupByLineageSearchQuery(
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);
Expand Down Expand Up @@ -226,17 +231,28 @@ private SearchResponse executeGroupByLineageSearchQuery(
}
}

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;
}
Expand Down

0 comments on commit 6a17c71

Please sign in to comment.