3
3
import static com .linkedin .metadata .aspect .models .graph .Edge .*;
4
4
import static com .linkedin .metadata .graph .elastic .ElasticSearchGraphService .*;
5
5
import static com .linkedin .metadata .search .utils .ESUtils .applyResultLimit ;
6
+ import static com .linkedin .metadata .search .utils .ESUtils .queryOptimize ;
6
7
7
8
import com .datahub .util .exception .ESQueryException ;
8
9
import com .google .common .annotations .VisibleForTesting ;
@@ -178,7 +179,7 @@ private static BoolQueryBuilder getAggregationFilter(
178
179
BoolQueryBuilder subFilter = QueryBuilders .boolQuery ();
179
180
TermQueryBuilder relationshipTypeTerm =
180
181
QueryBuilders .termQuery (RELATIONSHIP_TYPE , pair .getValue ().getType ()).caseInsensitive (true );
181
- subFilter .must (relationshipTypeTerm );
182
+ subFilter .filter (relationshipTypeTerm );
182
183
183
184
String sourceType ;
184
185
String destinationType ;
@@ -192,10 +193,10 @@ private static BoolQueryBuilder getAggregationFilter(
192
193
193
194
TermQueryBuilder sourceTypeTerm =
194
195
QueryBuilders .termQuery (SOURCE_TYPE , sourceType ).caseInsensitive (true );
195
- subFilter .must (sourceTypeTerm );
196
+ subFilter .filter (sourceTypeTerm );
196
197
TermQueryBuilder destinationTypeTerm =
197
198
QueryBuilders .termQuery (DESTINATION_TYPE , destinationType ).caseInsensitive (true );
198
- subFilter .must (destinationTypeTerm );
199
+ subFilter .filter (destinationTypeTerm );
199
200
return subFilter ;
200
201
}
201
202
@@ -261,6 +262,7 @@ public static BoolQueryBuilder buildQuery(
261
262
relationshipQuery .should (
262
263
QueryBuilders .termQuery (RELATIONSHIP_TYPE , relationshipType )));
263
264
relationshipQuery .minimumShouldMatch (1 );
265
+
264
266
finalQuery .filter (relationshipQuery );
265
267
}
266
268
@@ -1140,6 +1142,10 @@ private List<LineageRelationship> relationshipsGroupQuery(
1140
1142
1141
1143
Set <Urn > entityUrnSet = new HashSet <>(entityUrns );
1142
1144
1145
+ if (config .getSearch ().getGraph ().isQueryOptimization ()) {
1146
+ queryOptimize (baseQuery , false );
1147
+ }
1148
+
1143
1149
// Get search responses as a stream with pagination
1144
1150
Stream <SearchResponse > responseStream =
1145
1151
executeGroupByLineageSearchQuery (
@@ -1167,16 +1173,16 @@ private List<LineageRelationship> relationshipsGroupQuery(
1167
1173
private static BoolQueryBuilder getOutGoingEdgeQuery (
1168
1174
@ Nonnull Set <Urn > urns , @ Nonnull Set <EdgeInfo > outgoingEdges ) {
1169
1175
BoolQueryBuilder outgoingEdgeQuery = QueryBuilders .boolQuery ();
1170
- outgoingEdgeQuery .must (buildUrnFilters (urns , SOURCE ));
1171
- outgoingEdgeQuery .must (buildEdgeFilters (outgoingEdges ));
1176
+ outgoingEdgeQuery .filter (buildUrnFilters (urns , SOURCE ));
1177
+ outgoingEdgeQuery .filter (buildEdgeFilters (outgoingEdges ));
1172
1178
return outgoingEdgeQuery ;
1173
1179
}
1174
1180
1175
1181
private static BoolQueryBuilder getIncomingEdgeQuery (
1176
1182
@ Nonnull Set <Urn > urns , Set <EdgeInfo > incomingEdges ) {
1177
1183
BoolQueryBuilder incomingEdgeQuery = QueryBuilders .boolQuery ();
1178
- incomingEdgeQuery .must (buildUrnFilters (urns , DESTINATION ));
1179
- incomingEdgeQuery .must (buildEdgeFilters (incomingEdges ));
1184
+ incomingEdgeQuery .filter (buildUrnFilters (urns , DESTINATION ));
1185
+ incomingEdgeQuery .filter (buildEdgeFilters (incomingEdges ));
1180
1186
return incomingEdgeQuery ;
1181
1187
}
1182
1188
0 commit comments