Skip to content

Commit 322b0b4

Browse files
committed
Remove the index type from internal watcher indexes (elastic#39761)
This commit removes the "doc" type from watcher internal indexes. The template still carries the "_doc" type since that is needed for the internal representation. This impacts the .watches, .triggered-watches, and .watch-history indexes. External consumers do not need any changes since all external calls go through the _watcher API, and should not interact with the the .index directly. Relates elastic#38637
1 parent c23ff08 commit 322b0b4

File tree

42 files changed

+177
-173
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+177
-173
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/execution/TriggeredWatchStoreField.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@
88
public final class TriggeredWatchStoreField {
99

1010
public static final String INDEX_NAME = ".triggered_watches";
11-
public static final String DOC_TYPE = "doc";
1211
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/watch/Watch.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public class Watch implements ToXContentObject {
2626

2727
public static final String INCLUDE_STATUS_KEY = "include_status";
2828
public static final String INDEX = ".watches";
29-
public static final String DOC_TYPE = "doc";
3029

3130
private final String id;
3231
private final Trigger trigger;

x-pack/plugin/core/src/main/resources/triggered-watches.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"index.priority": 900
1010
},
1111
"mappings": {
12-
"doc": {
12+
"_doc": {
1313
"dynamic" : "strict",
1414
"properties": {
1515
"trigger_event": {

x-pack/plugin/core/src/main/resources/watch-history.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"index.format": 6
1010
},
1111
"mappings": {
12-
"doc": {
12+
"_doc": {
1313
"_meta": {
1414
"watcher-history-version": "${xpack.watcher.template.version}"
1515
},

x-pack/plugin/core/src/main/resources/watches.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"index.priority": 800
1010
},
1111
"mappings": {
12-
"doc": {
12+
"_doc": {
1313
"dynamic" : "strict",
1414
"properties": {
1515
"status": {

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/WatcherIndexingListener.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void setConfiguration(Configuration configuration) {
101101
*/
102102
@Override
103103
public Engine.Index preIndex(ShardId shardId, Engine.Index operation) {
104-
if (isWatchDocument(shardId.getIndexName(), operation.type())) {
104+
if (isWatchDocument(shardId.getIndexName())) {
105105
ZonedDateTime now = Instant.ofEpochMilli(clock.millis()).atZone(ZoneOffset.UTC);
106106
try {
107107
Watch watch = parser.parseWithSecrets(operation.id(), true, operation.source(), now, XContentType.JSON,
@@ -150,7 +150,7 @@ public Engine.Index preIndex(ShardId shardId, Engine.Index operation) {
150150
*/
151151
@Override
152152
public void postIndex(ShardId shardId, Engine.Index index, Exception ex) {
153-
if (isWatchDocument(shardId.getIndexName(), index.type())) {
153+
if (isWatchDocument(shardId.getIndexName())) {
154154
logger.debug(() -> new ParameterizedMessage("removing watch [{}] from trigger", index.id()), ex);
155155
triggerService.remove(index.id());
156156
}
@@ -166,7 +166,7 @@ public void postIndex(ShardId shardId, Engine.Index index, Exception ex) {
166166
*/
167167
@Override
168168
public Engine.Delete preDelete(ShardId shardId, Engine.Delete delete) {
169-
if (isWatchDocument(shardId.getIndexName(), delete.type())) {
169+
if (isWatchDocument(shardId.getIndexName())) {
170170
triggerService.remove(delete.id());
171171
}
172172

@@ -177,11 +177,10 @@ public Engine.Delete preDelete(ShardId shardId, Engine.Delete delete) {
177177
* Check if a supplied index and document matches the current configuration for watcher
178178
*
179179
* @param index The index to check for
180-
* @param docType The document type
181180
* @return true if this is a watch in the active watcher index, false otherwise
182181
*/
183-
private boolean isWatchDocument(String index, String docType) {
184-
return configuration.isIndexAndActive(index) && docType.equals(Watch.DOC_TYPE);
182+
private boolean isWatchDocument(String index) {
183+
return configuration.isIndexAndActive(index);
185184
}
186185

187186
/**

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/ActionBuilders.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,18 @@ public static EmailAction.Builder emailAction(EmailTemplate email) {
3434
return EmailAction.builder(email);
3535
}
3636

37+
/**
38+
* Types are deprecated and should not be used. use {@link #indexAction(String)}
39+
*/
40+
@Deprecated
3741
public static IndexAction.Builder indexAction(String index, String type) {
3842
return IndexAction.builder(index, type);
3943
}
4044

45+
public static IndexAction.Builder indexAction(String index) {
46+
return IndexAction.builder(index);
47+
}
48+
4149
public static JiraAction.Builder jiraAction(String account, MapBuilder<String, Object> fields) {
4250
return jiraAction(account, fields.immutableMap());
4351
}

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/index/IndexAction.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class IndexAction implements Action {
2929

3030
public static final String TYPE = "index";
3131

32-
@Nullable final String docType;
32+
@Nullable @Deprecated final String docType;
3333
@Nullable final String index;
3434
@Nullable final String docId;
3535
@Nullable final String executionTimeField;
@@ -40,6 +40,15 @@ public class IndexAction implements Action {
4040
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(IndexAction.class));
4141
public static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Specifying types in a watcher index action is deprecated.";
4242

43+
public IndexAction(@Nullable String index, @Nullable String docId,
44+
@Nullable String executionTimeField,
45+
@Nullable TimeValue timeout, @Nullable ZoneId dynamicNameTimeZone, @Nullable RefreshPolicy refreshPolicy) {
46+
this(index, null, docId, executionTimeField, timeout, dynamicNameTimeZone, refreshPolicy);
47+
}
48+
/**
49+
* Document types are deprecated, use constructor without docType
50+
*/
51+
@Deprecated
4352
public IndexAction(@Nullable String index, @Nullable String docType, @Nullable String docId,
4453
@Nullable String executionTimeField,
4554
@Nullable TimeValue timeout, @Nullable ZoneId dynamicNameTimeZone, @Nullable RefreshPolicy refreshPolicy) {
@@ -188,10 +197,18 @@ public static IndexAction parse(String watchId, String actionId, XContentParser
188197
return new IndexAction(index, docType, docId, executionTimeField, timeout, dynamicNameTimeZone, refreshPolicy);
189198
}
190199

200+
/**
201+
* Document types are deprecated, use {@link #builder(java.lang.String)}
202+
*/
203+
@Deprecated
191204
public static Builder builder(String index, String docType) {
192205
return new Builder(index, docType);
193206
}
194207

208+
public static Builder builder(String index) {
209+
return new Builder(index);
210+
}
211+
195212
public static class Result extends Action.Result {
196213

197214
private final XContentSource response;
@@ -278,11 +295,20 @@ public static class Builder implements Action.Builder<IndexAction> {
278295
ZoneId dynamicNameTimeZone;
279296
RefreshPolicy refreshPolicy;
280297

298+
/**
299+
* Document types are deprecated and should not be used. Use: {@link Builder#Builder(java.lang.String)}
300+
*/
301+
@Deprecated
281302
private Builder(String index, String docType) {
282303
this.index = index;
283304
this.docType = docType;
284305
}
285306

307+
private Builder(String index) {
308+
this.index = index;
309+
this.docType = null;
310+
}
311+
286312
public Builder setDocId(String docId) {
287313
this.docId = docId;
288314
return this;

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/execution/ExecutionService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ public void updateWatchStatus(Watch watch) throws IOException {
352352
.field(WatchField.STATUS.getPreferredName(), watch.status(), params)
353353
.endObject();
354354

355-
UpdateRequest updateRequest = new UpdateRequest(Watch.INDEX, Watch.DOC_TYPE, watch.id());
355+
UpdateRequest updateRequest = new UpdateRequest(Watch.INDEX, watch.id());
356356
updateRequest.doc(source);
357357
updateRequest.setIfSeqNo(watch.getSourceSeqNo());
358358
updateRequest.setIfPrimaryTerm(watch.getSourcePrimaryTerm());
@@ -501,7 +501,7 @@ public void executeTriggeredWatches(Collection<TriggeredWatch> triggeredWatches)
501501
*/
502502
private GetResponse getWatch(String id) {
503503
try (ThreadContext.StoredContext ignore = stashWithOrigin(client.threadPool().getThreadContext(), WATCHER_ORIGIN)) {
504-
GetRequest getRequest = new GetRequest(Watch.INDEX, Watch.DOC_TYPE, id).preference(Preference.LOCAL.type()).realtime(true);
504+
GetRequest getRequest = new GetRequest(Watch.INDEX, id).preference(Preference.LOCAL.type()).realtime(true);
505505
PlainActionFuture<GetResponse> future = PlainActionFuture.newFuture();
506506
client.get(getRequest, future);
507507
return future.actionGet();

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/execution/TriggeredWatchStore.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ public BulkResponse putAll(final List<TriggeredWatch> triggeredWatches) throws I
9696
private BulkRequest createBulkRequest(final List<TriggeredWatch> triggeredWatches) throws IOException {
9797
BulkRequest request = new BulkRequest();
9898
for (TriggeredWatch triggeredWatch : triggeredWatches) {
99-
IndexRequest indexRequest = new IndexRequest(TriggeredWatchStoreField.INDEX_NAME, TriggeredWatchStoreField.DOC_TYPE,
100-
triggeredWatch.id().value());
99+
IndexRequest indexRequest = new IndexRequest(TriggeredWatchStoreField.INDEX_NAME).id(triggeredWatch.id().value());
101100
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
102101
triggeredWatch.toXContent(builder, ToXContent.EMPTY_PARAMS);
103102
indexRequest.source(builder);
@@ -115,7 +114,7 @@ private BulkRequest createBulkRequest(final List<TriggeredWatch> triggeredWatche
115114
* @param wid The ID os the triggered watch id
116115
*/
117116
public void delete(Wid wid) {
118-
DeleteRequest request = new DeleteRequest(TriggeredWatchStoreField.INDEX_NAME, TriggeredWatchStoreField.DOC_TYPE, wid.value());
117+
DeleteRequest request = new DeleteRequest(TriggeredWatchStoreField.INDEX_NAME, wid.value());
119118
bulkProcessor.add(request);
120119
}
121120

0 commit comments

Comments
 (0)