Skip to content
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

ElasticsearchEnrichClient does not return taskId when waitForCompletion is set to false. #1692

Open
swatisuman1990 opened this issue Jan 20, 2025 · 0 comments

Comments

@swatisuman1990
Copy link

Below are the libraries I am using.
implementation group: 'org.springframework.data', name: 'spring-data-elasticsearch', version: '5.1.12'
implementation group: 'org.elasticsearch.client', name: 'elasticsearch-rest-client', version: '8.6.2'

Below is my code snippet.

private void executeEnrichPolicy(ElasticsearchEnrichClient enrichClient, String policyName) throws IOException {
        log.info("executing:{}", policyName);
        ApiTypeHelper.DANGEROUS_disableRequiredPropertiesCheck(true);
        ExecutePolicyRequest executePolicyRequest = ExecutePolicyRequest.of(e -> e.name(policyName).
                waitForCompletion(false));
        final ExecutePolicyResponse executePolicyResponse = enrichClient.executePolicy(executePolicyRequest);
        String taskId = executePolicyResponse.taskId();
        pollForTaskCompletion(taskId);
        ApiTypeHelper.DANGEROUS_disableRequiredPropertiesCheck(false);
        log.info("policy executed:{}", executePolicyResponse.status().toString());
    }

    @SneakyThrows
    private void pollForTaskCompletion(String taskId) {
        ElasticsearchTasksClient tasksClient = restHighLevelClient.tasks();
        while (true) {
            GetTasksRequest getTasksRequest = GetTasksRequest.of(builder -> builder.taskId(taskId));
            GetTasksResponse getTasksResponse = tasksClient.get(getTasksRequest);
            if (getTasksResponse.task() == null) {
                log.info("Task completed: {}", taskId);
                break;
            } else {
                log.info("Task {} is still running.", taskId);
            }
            Thread.sleep(60000);

        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant