Skip to content

Add timeout to synonyms put APIs to wait for synonyms system index to be searchable #126314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

carlosdelest
Copy link
Member

Closes #121441

Synonyms APIs use a system index to store synonyms as individual documents. These documents need to be searched in order to be retrieved from the analyzers.

When the system index has not been created yet, it is possible that creating the index need some time for the replicas to be available for search. Thus, an analyzer that is reloaded after the synonyms are created won't be able to retrieve the synonyms, and as a consequence we won't have synonyms for the index until a reload analyzer operation is performed.

This PR fixes this issue by retrieving the synonyms index health, and waiting for it to be green before reloading analyzers. As this can time out due to the index not being available, a default timeout is introduced (10s) that can be overriden in the request, with -1 meaning not to check the synonyms index availability.

@carlosdelest carlosdelest added >bug :Search Relevance/Analysis How text is split into tokens auto-backport Automatically create backport pull requests when merged Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v9.0.0 v8.9.0 v8.19.0 and removed v8.9.0 labels Apr 4, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @carlosdelest, I've created a changelog YAML for you.

@@ -15,11 +15,6 @@ setup:

- match: { result: "created" }

- do:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer need to do an explicit wait in tests, as it is done in the PUT operations themselves

@@ -120,67 +132,73 @@ public void testCreateTooManySynonymsUsingRuleUpdates() throws InterruptedExcept
int rulesToUpdate = randomIntBetween(1, 10);
int synonymsToCreate = maxSynonymSets - rulesToUpdate;
String synonymSetId = randomIdentifier();
synonymsManagementAPIService.putSynonymsSet(synonymSetId, randomSynonymsSet(synonymsToCreate), new ActionListener<>() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is not changed, the reformatting confused the diff

@@ -34,14 +36,16 @@ public class PutSynonymRuleAction extends ActionType<SynonymUpdateResponse> {
public static final PutSynonymRuleAction INSTANCE = new PutSynonymRuleAction();
public static final String NAME = "cluster:admin/synonym_rules/put";

public static final TimeValue DEFAULT_TIMEOUT = TimeValue.timeValueSeconds(10);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have used the default ACK timeout (30s) - seemed a bit too much, happy to hear thoughts

@@ -343,7 +353,13 @@ public void putSynonymsSet(String synonymSetId, SynonymRule[] synonymsSet, Actio
? UpdateSynonymsResultStatus.CREATED
: UpdateSynonymsResultStatus.UPDATED;

reloadAnalyzers(synonymSetId, false, bulkInsertResponseListener, updateSynonymsResultStatus);
ensureSynonymsSearchableAndReloadAnalyzers(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put actions need to ensure that synonyms are searchable before reloading

@@ -85,3 +79,69 @@ setup:
rule_id: "test-id-0"
body:
synonyms: "i-phone, iphone"

---
"Timeout can be specified":
Copy link
Member Author

@carlosdelest carlosdelest Apr 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These general validation tests were missing - adding them and the timeout validation tests

@@ -283,7 +283,7 @@ public class InternalUsers {
UsernamesField.SYNONYMS_USER_NAME,
new RoleDescriptor(
UsernamesField.SYNONYMS_ROLE_NAME,
null,
new String[] { "monitor" },
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retrieving cluster health means having monitor cluster privilege.

@carlosdelest carlosdelest marked this pull request as ready for review April 7, 2025 05:45
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-relevance (Team:Search Relevance)

@carlosdelest carlosdelest requested a review from a team April 7, 2025 05:46
@carlosdelest carlosdelest changed the title Add timeout to synonyms put APIs to wait for synonyms to be accessible Add timeout to synonyms put APIs to wait for synonyms system index to be searchable Apr 7, 2025
Copy link
Member

@benwtrent benwtrent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#121441 (comment)

This is my comment on the design. I do not think timeout is the right idea here.

@mayya-sharipova
Copy link
Contributor

I agree with @benwtrent , and also added my comments on the issue.

@carlosdelest
Copy link
Member Author

Closing in favour of using refresh parameter, see #126935

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged >bug :Search Relevance/Analysis How text is split into tokens Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v8.19.0 v9.0.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Synonyms API - Ensure system index is available when updating synonyms
4 participants