Skip to content

Commit 1700357

Browse files
authored
Fix org merge suggestions exceeding OpenSearch clause limit (#3004)
1 parent aa7f8c7 commit 1700357

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

services/apps/merge_suggestions_worker/src/activities/organizationMergeSuggestions.ts

+10-15
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ export async function getOrganizationMergeSuggestions(
122122
return []
123123
}
124124

125+
const noMergeIds = await organizationMergeSuggestionsRepo.findNoMergeIds(fullOrg.id)
126+
const excludeIds = [fullOrg.id]
127+
128+
if (noMergeIds && noMergeIds.length > 0) {
129+
excludeIds.push(...noMergeIds)
130+
}
131+
125132
const identitiesShould = []
126133
const identitiesPartialQuery = {
127134
should: [
@@ -145,8 +152,8 @@ export async function getOrganizationMergeSuggestions(
145152
minimum_should_match: 1,
146153
must_not: [
147154
{
148-
term: {
149-
uuid_organizationId: fullOrg.id,
155+
terms: {
156+
uuid_organizationId: excludeIds,
150157
},
151158
},
152159
],
@@ -166,7 +173,7 @@ export async function getOrganizationMergeSuggestions(
166173
)
167174

168175
// limit to prevent exceeding OpenSearch's maxClauseCount (1024)
169-
for (const identity of identities.slice(0, 140)) {
176+
for (const identity of identities.slice(0, 120)) {
170177
if (identity.value.length > 0) {
171178
// weak identity search
172179
identitiesShould.push({
@@ -236,18 +243,6 @@ export async function getOrganizationMergeSuggestions(
236243
identitiesPartialQuery.should.pop()
237244
}
238245

239-
const noMergeIds = await organizationMergeSuggestionsRepo.findNoMergeIds(fullOrg.id)
240-
241-
if (noMergeIds && noMergeIds.length > 0) {
242-
for (const noMergeId of noMergeIds) {
243-
identitiesPartialQuery.must_not.push({
244-
term: {
245-
uuid_organizationId: noMergeId,
246-
},
247-
})
248-
}
249-
}
250-
251246
const similarOrganizationsQueryBody = {
252247
query: {
253248
bool: identitiesPartialQuery,

0 commit comments

Comments
 (0)