Skip to content

Commit c311fff

Browse files
Merge remote-tracking branch 'elastic/main' into skip-can-match-on-batched
2 parents 54a1c1e + feb44c5 commit c311fff

File tree

7 files changed

+45
-4
lines changed

7 files changed

+45
-4
lines changed

docs/changelog/124708.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 124708
2+
summary: Throw exception for unknown token in RestIndexPutAliasAction
3+
area: Indices APIs
4+
type: enhancement
5+
issues: []

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.put_alias/10_basic.yml

+27
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,30 @@
103103
index: test_index
104104
name: test_alias
105105
- match: {test_index.aliases.test_alias: {"filter": {"range": {"date_nanos_field": {"gt": "now-7d/d"}}}}}
106+
107+
---
108+
"Throw exception for unknown token":
109+
- requires:
110+
cluster_features: [ "index.throw_exception_for_unknown_token_in_rest_index_put_alias_action" ]
111+
reason: "Throw exception for unknown token in RestIndexPutAliasAction"
112+
113+
- do:
114+
indices.create:
115+
index: test_index
116+
117+
- do:
118+
catch: /Unsupported field \[foo\]/
119+
indices.put_alias:
120+
index: test_index
121+
name: test_alias
122+
body:
123+
is_write_index: true
124+
foo: "bar"
125+
126+
- do:
127+
catch: / Unexpected token \[START_ARRAY\]/
128+
indices.put_alias:
129+
index: test_index
130+
name: test_alias
131+
body:
132+
routing: [ "routing" ]

server/src/main/java/org/elasticsearch/index/IndexFeatures.java

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public Set<NodeFeature> getFeatures() {
2525

2626
private static final NodeFeature SYNONYMS_SET_LENIENT_ON_NON_EXISTING = new NodeFeature("index.synonyms_set_lenient_on_non_existing");
2727

28+
private static final NodeFeature THROW_EXCEPTION_FOR_UNKNOWN_TOKEN_IN_REST_INDEX_PUT_ALIAS_ACTION = new NodeFeature(
29+
"index.throw_exception_for_unknown_token_in_rest_index_put_alias_action"
30+
);
31+
2832
private static final NodeFeature THROW_EXCEPTION_ON_INDEX_CREATION_IF_UNSUPPORTED_VALUE_TYPE_IN_ALIAS = new NodeFeature(
2933
"index.throw_exception_on_index_creation_if_unsupported_value_type_in_alias"
3034
);
@@ -34,6 +38,7 @@ public Set<NodeFeature> getTestFeatures() {
3438
return Set.of(
3539
LOGSDB_NO_HOST_NAME_FIELD,
3640
SYNONYMS_SET_LENIENT_ON_NON_EXISTING,
41+
THROW_EXCEPTION_FOR_UNKNOWN_TOKEN_IN_REST_INDEX_PUT_ALIAS_ACTION,
3742
THROW_EXCEPTION_ON_INDEX_CREATION_IF_UNSUPPORTED_VALUE_TYPE_IN_ALIAS
3843
);
3944
}

server/src/main/java/org/elasticsearch/index/shard/IndexShard.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2652,7 +2652,7 @@ public void onSettingsChanged() {
26522652
}
26532653

26542654
/**
2655-
* Acquires a lock on the translog files and Lucene soft-deleted documents to prevent them from being trimmed
2655+
* Acquires a lock on Lucene soft-deleted documents to prevent them from being trimmed
26562656
*/
26572657
public Closeable acquireHistoryRetentionLock() {
26582658
return getEngine().acquireHistoryRetentionLock();

server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndexPutAliasAction.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
1212
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
1313
import org.elasticsearch.client.internal.node.NodeClient;
14+
import org.elasticsearch.common.ParsingException;
1415
import org.elasticsearch.common.Strings;
1516
import org.elasticsearch.rest.BaseRestHandler;
1617
import org.elasticsearch.rest.RestRequest;
@@ -30,7 +31,6 @@
3031

3132
@ServerlessScope(Scope.PUBLIC)
3233
public class RestIndexPutAliasAction extends BaseRestHandler {
33-
3434
@Override
3535
public List<Route> routes() {
3636
return List.of(
@@ -90,11 +90,15 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
9090
searchRouting = parser.textOrNull();
9191
} else if ("is_write_index".equals(currentFieldName)) {
9292
writeIndex = parser.booleanValue();
93+
} else {
94+
throw new IllegalArgumentException("Unsupported field [" + currentFieldName + "]");
9395
}
9496
} else if (token == XContentParser.Token.START_OBJECT) {
9597
if ("filter".equals(currentFieldName)) {
9698
filter = parser.mapOrdered();
9799
}
100+
} else if (token != XContentParser.Token.END_OBJECT) {
101+
throw new ParsingException(parser.getTokenLocation(), "Unexpected token [" + token + "]");
98102
}
99103
}
100104
}

x-pack/plugin/esql/qa/security/src/javaRestTest/java/org/elasticsearch/xpack/esql/EsqlSecurityIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ private void createDataStreamDocuments() throws IOException {
995995
}
996996

997997
private void createDataStreamAlias() throws IOException {
998-
Request request = new Request("PUT", "_alias");
998+
Request request = new Request("POST", "_aliases");
999999
request.setJsonEntity("""
10001000
{
10011001
"actions": [

x-pack/plugin/security/qa/multi-cluster/src/javaRestTest/java/org/elasticsearch/xpack/remotecluster/RemoteClusterSecurityDataStreamEsqlRcs1IT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ private static void createDataStreamDocuments(CheckedFunction<Request, Response,
270270
}
271271

272272
private static void createDataStreamAlias(CheckedFunction<Request, Response, Exception> requestConsumer) throws Exception {
273-
Request request = new Request("PUT", "_alias");
273+
Request request = new Request("POST", "_aliases");
274274
request.setJsonEntity("""
275275
{
276276
"actions": [

0 commit comments

Comments
 (0)