Skip to content

Commit 163fa8c

Browse files
authored
Remove create parameter from put query ruleset API call (#96883)
1 parent 27dec1a commit 163fa8c

File tree

8 files changed

+15
-64
lines changed

8 files changed

+15
-64
lines changed

rest-api-spec/src/main/resources/rest-api-spec/api/query_ruleset.put.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@
3131
}
3232
]
3333
},
34-
"params": {
35-
"create": {
36-
"type": "boolean",
37-
"description": "If true, requires that a query_ruleset with the specified resource_id does not already exist. (default: false)"
38-
}
39-
},
4034
"body": {
4135
"description": "The query ruleset configuration, including `rules`",
4236
"required": true

x-pack/plugin/ent-search/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/entsearch/200_query_ruleset_put.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
'Create Query Ruleset - Resource already exists':
3838
- do:
3939
query_ruleset.put:
40-
create: true
4140
ruleset_id: test-query-ruleset-recreating
4241
body:
4342
ruleset_id: 'test-query-ruleset-recreating'
@@ -55,9 +54,7 @@
5554
- match: { result: 'created' }
5655

5756
- do:
58-
catch: conflict
5957
query_ruleset.put:
60-
create: true
6158
ruleset_id: test-query-ruleset-recreating
6259
body:
6360
ruleset_id: 'test-query-ruleset-recreating'
@@ -72,7 +69,7 @@
7269
ids:
7370
- 'id2'
7471

75-
- match: { error.type: 'version_conflict_engine_exception' }
72+
- match: { result: 'updated' }
7673

7774
---
7875
'Create Query Ruleset - Insufficient privilege':
@@ -84,7 +81,6 @@
8481
headers: { Authorization: "Basic ZW50c2VhcmNoLXVzZXI6ZW50c2VhcmNoLXVzZXItcGFzc3dvcmQ=" } # user
8582
query_ruleset.put:
8683
ruleset_id: forbidden-query-ruleset
87-
create: true
8884
body:
8985
ruleset_id: 'forbidden-query-ruleset'
9086
rules:

x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/rules/QueryRulesIndexService.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,13 @@ private List<QueryRuleCriteria> parseCriteria(List<Map<String, Object>> rawCrite
207207
* Creates or updates the {@link QueryRuleset} in the underlying index.
208208
*
209209
* @param queryRuleset The query ruleset object.
210-
* @param create If true, a query ruleset with the specified unique identifier must not already exist
211210
* @param listener The action listener to invoke on response/failure.
212211
*/
213-
public void putQueryRuleset(QueryRuleset queryRuleset, boolean create, ActionListener<IndexResponse> listener) {
212+
public void putQueryRuleset(QueryRuleset queryRuleset, ActionListener<IndexResponse> listener) {
214213
try {
215-
DocWriteRequest.OpType opType = (create ? DocWriteRequest.OpType.CREATE : DocWriteRequest.OpType.INDEX);
216214
final IndexRequest indexRequest = new IndexRequest(QUERY_RULES_ALIAS_NAME).opType(DocWriteRequest.OpType.INDEX)
217215
.id(queryRuleset.id())
218-
.opType(opType)
216+
.opType(DocWriteRequest.OpType.INDEX)
219217
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
220218
.source(queryRuleset.toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS));
221219
clientWithOrigin.index(indexRequest, listener);

x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/rules/action/PutQueryRulesetAction.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,18 @@ public PutQueryRulesetAction() {
4141
public static class Request extends ActionRequest {
4242

4343
private final QueryRuleset queryRuleset;
44-
private final boolean create;
4544

4645
public Request(StreamInput in) throws IOException {
4746
super(in);
4847
this.queryRuleset = new QueryRuleset(in);
49-
this.create = in.readBoolean();
5048
}
5149

52-
public Request(QueryRuleset queryRuleset, boolean create) {
50+
public Request(QueryRuleset queryRuleset) {
5351
this.queryRuleset = queryRuleset;
54-
this.create = create;
5552
}
5653

57-
public Request(String rulesetId, boolean create, BytesReference content, XContentType contentType) {
54+
public Request(String rulesetId, BytesReference content, XContentType contentType) {
5855
this.queryRuleset = QueryRuleset.fromXContentBytes(rulesetId, content, contentType);
59-
this.create = create;
6056
}
6157

6258
@Override
@@ -79,28 +75,23 @@ public ActionRequestValidationException validate() {
7975
public void writeTo(StreamOutput out) throws IOException {
8076
super.writeTo(out);
8177
queryRuleset.writeTo(out);
82-
out.writeBoolean(create);
8378
}
8479

8580
public QueryRuleset queryRuleset() {
8681
return queryRuleset;
8782
}
8883

89-
public boolean create() {
90-
return create;
91-
}
92-
9384
@Override
9485
public boolean equals(Object o) {
9586
if (this == o) return true;
9687
if (o == null || getClass() != o.getClass()) return false;
9788
Request request = (Request) o;
98-
return create == request.create && Objects.equals(queryRuleset, request.queryRuleset);
89+
return Objects.equals(queryRuleset, request.queryRuleset);
9990
}
10091

10192
@Override
10293
public int hashCode() {
103-
return Objects.hash(queryRuleset, create);
94+
return Objects.hash(queryRuleset);
10495
}
10596
}
10697

x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/rules/action/RestPutQueryRulesetAction.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public List<Route> routes() {
4242
protected RestChannelConsumer innerPrepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
4343
PutQueryRulesetAction.Request request = new PutQueryRulesetAction.Request(
4444
restRequest.param("ruleset_id"),
45-
restRequest.paramAsBoolean("create", false),
4645
restRequest.content(),
4746
restRequest.getXContentType()
4847
);

x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/rules/action/TransportPutQueryRulesetAction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ public TransportPutQueryRulesetAction(TransportService transportService, ActionF
2929
@Override
3030
protected void doExecute(Task task, PutQueryRulesetAction.Request request, ActionListener<PutQueryRulesetAction.Response> listener) {
3131
QueryRuleset queryRuleset = request.queryRuleset();
32-
boolean create = request.create();
33-
systemIndexService.putQueryRuleset(queryRuleset, create, listener.map(r -> new PutQueryRulesetAction.Response(r.getResult())));
32+
systemIndexService.putQueryRuleset(queryRuleset, listener.map(r -> new PutQueryRulesetAction.Response(r.getResult())));
3433

3534
}
3635
}

x-pack/plugin/ent-search/src/test/java/org/elasticsearch/xpack/application/rules/QueryRulesIndexServiceTests.java

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.elasticsearch.action.delete.DeleteResponse;
1313
import org.elasticsearch.action.index.IndexResponse;
1414
import org.elasticsearch.common.settings.Settings;
15-
import org.elasticsearch.index.engine.VersionConflictEngineException;
1615
import org.elasticsearch.indices.SystemIndexDescriptor;
1716
import org.elasticsearch.plugins.Plugin;
1817
import org.elasticsearch.plugins.SystemIndexPlugin;
@@ -59,31 +58,6 @@ public void testEmptyState() throws Exception {
5958
assertThat(listResults.totalResults(), equalTo(0L));
6059
}
6160

62-
public void testCreateQueryRuleset() throws Exception {
63-
final QueryRule myQueryRule1 = new QueryRule(
64-
"my_rule1",
65-
QueryRuleType.PINNED,
66-
List.of(new QueryRuleCriteria(CriteriaType.EXACT, "query_string", "foo")),
67-
Map.of("ids", List.of("id1", "id2"))
68-
);
69-
final QueryRule myQueryRule2 = new QueryRule(
70-
"my_rule2",
71-
QueryRuleType.PINNED,
72-
List.of(new QueryRuleCriteria(CriteriaType.EXACT, "query_string", "bar")),
73-
Map.of("ids", List.of("id3", "id4"))
74-
);
75-
final QueryRuleset myQueryRuleset = new QueryRuleset("my_ruleset", List.of(myQueryRule1, myQueryRule2));
76-
77-
IndexResponse resp = awaitPutQueryRuleset(myQueryRuleset, true);
78-
assertThat(resp.status(), equalTo(RestStatus.CREATED));
79-
assertThat(resp.getIndex(), equalTo(QUERY_RULES_CONCRETE_INDEX_NAME));
80-
81-
QueryRuleset getQueryRuleset = awaitGetQueryRuleset(myQueryRuleset.id());
82-
assertThat(getQueryRuleset, equalTo(myQueryRuleset));
83-
84-
expectThrows(VersionConflictEngineException.class, () -> awaitPutQueryRuleset(myQueryRuleset, true));
85-
}
86-
8761
public void testUpdateQueryRuleset() throws Exception {
8862
{
8963
final QueryRule myQueryRule1 = new QueryRule(
@@ -93,7 +67,7 @@ public void testUpdateQueryRuleset() throws Exception {
9367
Map.of("ids", List.of("id1", "id2"))
9468
);
9569
final QueryRuleset myQueryRuleset = new QueryRuleset("my_ruleset", Collections.singletonList(myQueryRule1));
96-
IndexResponse resp = awaitPutQueryRuleset(myQueryRuleset, false);
70+
IndexResponse resp = awaitPutQueryRuleset(myQueryRuleset);
9771
assertThat(resp.status(), anyOf(equalTo(RestStatus.CREATED), equalTo(RestStatus.OK)));
9872
assertThat(resp.getIndex(), equalTo(QUERY_RULES_CONCRETE_INDEX_NAME));
9973

@@ -114,7 +88,7 @@ public void testUpdateQueryRuleset() throws Exception {
11488
Map.of("docs", List.of(Map.of("_index", "my_index1", "_id", "id3"), Map.of("_index", "my_index2", "_id", "id4")))
11589
);
11690
final QueryRuleset myQueryRuleset = new QueryRuleset("my_ruleset", List.of(myQueryRule1, myQueryRule2));
117-
IndexResponse newResp = awaitPutQueryRuleset(myQueryRuleset, false);
91+
IndexResponse newResp = awaitPutQueryRuleset(myQueryRuleset);
11892
assertThat(newResp.status(), equalTo(RestStatus.OK));
11993
assertThat(newResp.getIndex(), equalTo(QUERY_RULES_CONCRETE_INDEX_NAME));
12094
QueryRuleset getQueryRuleset = awaitGetQueryRuleset(myQueryRuleset.id());
@@ -140,7 +114,7 @@ public void testListQueryRulesets() throws Exception {
140114
);
141115
final QueryRuleset myQueryRuleset = new QueryRuleset("my_ruleset_" + i, rules);
142116

143-
IndexResponse resp = awaitPutQueryRuleset(myQueryRuleset, false);
117+
IndexResponse resp = awaitPutQueryRuleset(myQueryRuleset);
144118
assertThat(resp.status(), equalTo(RestStatus.CREATED));
145119
assertThat(resp.getIndex(), equalTo(QUERY_RULES_CONCRETE_INDEX_NAME));
146120
}
@@ -188,7 +162,7 @@ public void testDeleteQueryRuleset() throws Exception {
188162
Map.of("ids", List.of("id3", "id4"))
189163
);
190164
final QueryRuleset myQueryRuleset = new QueryRuleset("my_ruleset", List.of(myQueryRule1, myQueryRule2));
191-
IndexResponse resp = awaitPutQueryRuleset(myQueryRuleset, false);
165+
IndexResponse resp = awaitPutQueryRuleset(myQueryRuleset);
192166
assertThat(resp.status(), anyOf(equalTo(RestStatus.CREATED), equalTo(RestStatus.OK)));
193167
assertThat(resp.getIndex(), equalTo(QUERY_RULES_CONCRETE_INDEX_NAME));
194168

@@ -201,11 +175,11 @@ public void testDeleteQueryRuleset() throws Exception {
201175
expectThrows(ResourceNotFoundException.class, () -> awaitGetQueryRuleset("my_ruleset"));
202176
}
203177

204-
private IndexResponse awaitPutQueryRuleset(QueryRuleset queryRuleset, boolean create) throws Exception {
178+
private IndexResponse awaitPutQueryRuleset(QueryRuleset queryRuleset) throws Exception {
205179
CountDownLatch latch = new CountDownLatch(1);
206180
final AtomicReference<IndexResponse> resp = new AtomicReference<>(null);
207181
final AtomicReference<Exception> exc = new AtomicReference<>(null);
208-
queryRulesIndexService.putQueryRuleset(queryRuleset, create, new ActionListener<>() {
182+
queryRulesIndexService.putQueryRuleset(queryRuleset, new ActionListener<>() {
209183
@Override
210184
public void onResponse(IndexResponse indexResponse) {
211185
resp.set(indexResponse);

x-pack/plugin/ent-search/src/test/java/org/elasticsearch/xpack/application/rules/action/PutQueryRulesetActionRequestSerializingTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ protected Writeable.Reader<PutQueryRulesetAction.Request> instanceReader() {
2020

2121
@Override
2222
protected PutQueryRulesetAction.Request createTestInstance() {
23-
return new PutQueryRulesetAction.Request(SearchApplicationTestUtils.randomQueryRuleset(), randomBoolean());
23+
return new PutQueryRulesetAction.Request(SearchApplicationTestUtils.randomQueryRuleset());
2424
}
2525

2626
@Override

0 commit comments

Comments
 (0)