Skip to content

Commit 2ee4f1b

Browse files
authored
Fixes to task result index mapping (#50359)
The built-in mapping for the tasks result index still has a mapping type defined; while this does not matter for index creation, as we still have a create method that takes a top-level type, it does matter for updates. In combination with a separate bug, that the built-in mapping has not incremented its meta version, this meant that tasks submitted to a cluster with an already existing task index would attempt to update the mappings on that index, and fail due to the top-level type. This commit fixes the mapping to have a top-level mapping of _doc, and also updates the meta version so that we do not update mappings on every new task. It also adds a test that explicitly runs two asynchronous tasks to ensure that the mappings do not cause a failure. Fixes #50248
1 parent b8cae37 commit 2ee4f1b

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

server/src/main/java/org/elasticsearch/tasks/TaskResultsService.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ public class TaskResultsService {
6767

6868
public static final String TASK_INDEX = ".tasks";
6969

70-
public static final String TASK_TYPE = "task";
71-
7270
public static final String TASK_RESULT_INDEX_MAPPING_FILE = "task-index-mapping.json";
7371

7472
public static final String TASK_RESULT_MAPPING_VERSION_META_FIELD = "version";
@@ -103,7 +101,7 @@ public void storeResult(TaskResult taskResult, ActionListener<Void> listener) {
103101
CreateIndexRequest createIndexRequest = new CreateIndexRequest();
104102
createIndexRequest.settings(taskResultIndexSettings());
105103
createIndexRequest.index(TASK_INDEX);
106-
createIndexRequest.mapping(TASK_TYPE, taskResultIndexMapping(), XContentType.JSON);
104+
createIndexRequest.mapping(taskResultIndexMapping());
107105
createIndexRequest.cause("auto(task api)");
108106

109107
client.admin().indices().create(createIndexRequest, new ActionListener<CreateIndexResponse>() {

server/src/main/resources/org/elasticsearch/tasks/task-index-mapping.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"task" : {
2+
"_doc" : {
33
"_meta": {
4-
"version": 2
4+
"version": 3
55
},
66
"dynamic" : "strict",
77
"properties" : {

server/src/test/java/org/elasticsearch/action/admin/cluster/node/tasks/TasksIT.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,13 @@ public void testTaskStoringSuccessfulResult() throws Exception {
768768
GetTaskResponse getResponse = expectFinishedTask(taskId);
769769
assertEquals(result, getResponse.getTask().getResponseAsMap());
770770
assertNull(getResponse.getTask().getError());
771+
772+
// run it again to check that the tasks index has been successfully created and can be re-used
773+
client().execute(TestTaskPlugin.TestTaskAction.INSTANCE, request).get();
774+
775+
events = findEvents(TestTaskPlugin.TestTaskAction.NAME, Tuple::v1);
776+
777+
assertEquals(2, events.size());
771778
}
772779

773780
public void testTaskStoringFailureResult() throws Exception {

0 commit comments

Comments
 (0)