Skip to content

Commit 56fcb75

Browse files
author
Kerem Sahin
committed
Revert "feat: Make max aggregation bucket size configurable"
This reverts commit f31107a.
1 parent f31107a commit 56fcb75

4 files changed

Lines changed: 4 additions & 38 deletions

File tree

dao-impl/elasticsearch-dao/src/main/java/com/linkedin/metadata/dao/search/ESSearchDAO.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@
5555
@Slf4j
5656
public class ESSearchDAO<DOCUMENT extends RecordTemplate> extends BaseSearchDAO<DOCUMENT> {
5757

58+
private static final Integer DEFAULT_TERM_BUCKETS_SIZE_100 = 100;
5859
private static final String URN_FIELD = "urn";
5960

6061
private RestHighLevelClient _client;
6162
private BaseSearchConfig<DOCUMENT> _config;
6263
private BaseESAutoCompleteQuery _autoCompleteQueryForLowCardFields;
6364
private BaseESAutoCompleteQuery _autoCompleteQueryForHighCardFields;
64-
private int _maxTermBucketSize = 100;
6565

6666
// TODO: Currently takes elastic search client, in future, can take other clients such as galene
6767
// TODO: take params and settings needed to create the client
@@ -254,7 +254,7 @@ private void buildAggregations(@Nonnull SearchSourceBuilder searchSourceBuilder,
254254
@Nullable Filter filter) {
255255
Set<String> facetFields = _config.getFacetFields();
256256
for (String facet : facetFields) {
257-
AggregationBuilder aggBuilder = AggregationBuilders.terms(facet).field(facet).size(_maxTermBucketSize);
257+
AggregationBuilder aggBuilder = AggregationBuilders.terms(facet).field(facet).size(DEFAULT_TERM_BUCKETS_SIZE_100);
258258
Optional.ofNullable(filter).map(Filter::getCriteria).ifPresent(criteria -> {
259259
for (Criterion criterion : criteria) {
260260
if (!facetFields.contains(criterion.getField()) || criterion.getField().equals(facet)) {
@@ -446,16 +446,4 @@ private Urn getUrnFromSearchHit(@Nonnull SearchHit hit) {
446446
throw new RuntimeException("Invalid urn in search document " + e);
447447
}
448448
}
449-
450-
/**
451-
* Sets max term bucket size in the aggregation results.
452-
*
453-
* <p>The default value might not always be good enough when aggregation happens on a high cardinality field.
454-
* Using a high default instead is also not ideal because of potential query performance degradation.
455-
* Instead, entities which have a rare use case of aggregating over high cardinality fields can use this method
456-
* to configure the aggregation behavior.
457-
*/
458-
public void setMaxTermBucketSize(int maxTermBucketSize) {
459-
_maxTermBucketSize = maxTermBucketSize;
460-
}
461449
}

dao-impl/elasticsearch-dao/src/test/java/com/linkedin/metadata/dao/search/ESSearchDAOTest.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.elasticsearch.action.search.SearchResponse;
2929
import org.elasticsearch.search.SearchHit;
3030
import org.elasticsearch.search.SearchHits;
31-
import org.elasticsearch.search.aggregations.AggregationBuilders;
3231
import org.testng.annotations.BeforeMethod;
3332
import org.testng.annotations.Test;
3433

@@ -213,23 +212,6 @@ public void testPreferenceInSearchQuery() {
213212
assertEquals(searchRequest.preference(), preference);
214213
}
215214

216-
@Test
217-
public void testSetMaxTermBucketSize() {
218-
String facetFieldName = "value";
219-
Filter filter = QueryUtils.newFilter(Collections.singletonMap(facetFieldName, "dummy"));
220-
221-
// Default max term bucket size
222-
SearchRequest searchRequest = _searchDAO.constructSearchQuery("dummy", filter, null, null, 0, 10);
223-
assertEquals(searchRequest.source().aggregations().getAggregatorFactories().get(0),
224-
AggregationBuilders.terms(facetFieldName).field(facetFieldName).size(100));
225-
226-
// Modified max term bucket size
227-
_searchDAO.setMaxTermBucketSize(5);
228-
searchRequest = _searchDAO.constructSearchQuery("dummy", filter, null, null, 0, 10);
229-
assertEquals(searchRequest.source().aggregations().getAggregatorFactories().get(0),
230-
AggregationBuilders.terms(facetFieldName).field(facetFieldName).size(5));
231-
}
232-
233215
private static SearchHit makeSearchHit(int id) {
234216
SearchHit hit = mock(SearchHit.class);
235217
Map<String, Object> sourceMap = new HashMap<>();

dao-impl/elasticsearch-dao/src/test/java/com/linkedin/metadata/dao/search/TestSearchConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
import com.linkedin.testing.EntityDocument;
44
import java.util.Collections;
5+
import java.util.HashSet;
56
import java.util.Set;
67
import javax.annotation.Nonnull;
78

89
public class TestSearchConfig extends BaseSearchConfig<EntityDocument> {
910
@Override
1011
@Nonnull
1112
public Set<String> getFacetFields() {
12-
return Collections.singleton("value");
13+
return Collections.unmodifiableSet(new HashSet<>());
1314
}
1415

1516
@Override

testing/test-models/src/main/pegasus/com/linkedin/testing/EntityDocument.pdl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,4 @@ record EntityDocument {
1111
* For unit tests
1212
*/
1313
urn: Urn
14-
15-
/**
16-
* For unit tests
17-
*/
18-
value: optional string
1914
}

0 commit comments

Comments
 (0)