Skip to content

Commit a282e27

Browse files
authored
Merge branch 'main' into markjhoy/default_token_pruning_sparse_vector
2 parents 21323e4 + feb44c5 commit a282e27

File tree

25 files changed

+769
-204
lines changed

25 files changed

+769
-204
lines changed

docs/changelog/124708.yaml

Lines changed: 5 additions & 0 deletions
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: []

docs/changelog/124737.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 124737
2+
summary: Throw exception for unsupported values type in Alias
3+
area: Indices APIs
4+
type: enhancement
5+
issues: []

qa/smoke-test-http/src/internalClusterTest/java/org/elasticsearch/http/SearchRestCancellationIT.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import org.apache.http.nio.entity.NByteArrayEntity;
1313
import org.apache.logging.log4j.LogManager;
1414
import org.apache.lucene.util.SetOnce;
15-
import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
16-
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
1715
import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
1816
import org.elasticsearch.action.bulk.BulkRequestBuilder;
1917
import org.elasticsearch.action.search.MultiSearchRequest;
@@ -46,7 +44,6 @@
4644
import java.util.ArrayList;
4745
import java.util.Collection;
4846
import java.util.Collections;
49-
import java.util.HashMap;
5047
import java.util.List;
5148
import java.util.Map;
5249
import java.util.concurrent.CancellationException;
@@ -94,7 +91,7 @@ public void testAutomaticCancellationMultiSearchDuringQueryPhase() throws Except
9491
}
9592

9693
void verifyCancellationDuringQueryPhase(String searchAction, Request searchRequest) throws Exception {
97-
Map<String, String> nodeIdToName = readNodesInfo();
94+
Map<String, String> nodeIdToName = nodeIdsToNames();
9895

9996
List<ScriptedBlockPlugin> plugins = initBlockFactory();
10097
indexTestData();
@@ -137,7 +134,7 @@ public void testAutomaticCancellationMultiSearchDuringFetchPhase() throws Except
137134
}
138135

139136
void verifyCancellationDuringFetchPhase(String searchAction, Request searchRequest) throws Exception {
140-
Map<String, String> nodeIdToName = readNodesInfo();
137+
Map<String, String> nodeIdToName = nodeIdsToNames();
141138

142139
List<ScriptedBlockPlugin> plugins = initBlockFactory();
143140
indexTestData();
@@ -153,16 +150,6 @@ void verifyCancellationDuringFetchPhase(String searchAction, Request searchReque
153150
expectThrows(CancellationException.class, future::actionGet);
154151
}
155152

156-
private static Map<String, String> readNodesInfo() {
157-
Map<String, String> nodeIdToName = new HashMap<>();
158-
NodesInfoResponse nodesInfoResponse = clusterAdmin().prepareNodesInfo().get();
159-
assertFalse(nodesInfoResponse.hasFailures());
160-
for (NodeInfo node : nodesInfoResponse.getNodes()) {
161-
nodeIdToName.put(node.getNode().getId(), node.getNode().getName());
162-
}
163-
return nodeIdToName;
164-
}
165-
166153
private static void ensureSearchTaskIsCancelled(String transportAction, Function<String, String> nodeIdToName) throws Exception {
167154
SetOnce<TaskInfo> searchTask = new SetOnce<>();
168155
ListTasksResponse listTasksResponse = clusterAdmin().prepareListTasks().get();

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,38 @@
8686
- is_false: test_index.aliases.test_clias.index_routing
8787
- is_false: test_index.aliases.test_clias.search_routing
8888

89+
---
90+
"Throw exception for unsupported value type":
91+
- requires:
92+
cluster_features: [ "index.throw_exception_on_index_creation_if_unsupported_value_type_in_alias" ]
93+
reason: "Throw exception on index creation if unsupported value type in alias"
94+
95+
- do:
96+
catch: /Unsupported String type value \[true\] for field \[is_write_index\] in alias \[test_alias\]/
97+
indices.create:
98+
index: test_index
99+
body:
100+
mappings:
101+
properties:
102+
field:
103+
type: text
104+
aliases:
105+
test_alias:
106+
is_write_index: "true"
107+
108+
- do:
109+
catch: /Unsupported boolean type value \[true\] for field \[routing\] in alias \[test_alias\]/
110+
indices.create:
111+
index: test_index
112+
body:
113+
mappings:
114+
properties:
115+
field:
116+
type: text
117+
aliases:
118+
test_alias:
119+
routing: true
120+
89121
---
90122
"Create index with write aliases":
91123

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

Lines changed: 27 additions & 0 deletions
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/action/admin/indices/alias/Alias.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,32 @@ public static Alias fromXContent(XContentParser parser) throws IOException {
257257
alias.indexRouting(parser.text());
258258
} else if (SEARCH_ROUTING.match(currentFieldName, parser.getDeprecationHandler())) {
259259
alias.searchRouting(parser.text());
260+
} else {
261+
throw new IllegalArgumentException(
262+
"Unsupported String type value ["
263+
+ parser.text()
264+
+ "] for field ["
265+
+ currentFieldName
266+
+ "] in alias ["
267+
+ alias.name
268+
+ "]"
269+
);
260270
}
261271
} else if (token == XContentParser.Token.VALUE_BOOLEAN) {
262272
if (IS_WRITE_INDEX.match(currentFieldName, parser.getDeprecationHandler())) {
263273
alias.writeIndex(parser.booleanValue());
264274
} else if (IS_HIDDEN.match(currentFieldName, parser.getDeprecationHandler())) {
265275
alias.isHidden(parser.booleanValue());
276+
} else {
277+
throw new IllegalArgumentException(
278+
"Unsupported boolean type value ["
279+
+ parser.text()
280+
+ "] for field ["
281+
+ currentFieldName
282+
+ "] in alias ["
283+
+ alias.name
284+
+ "]"
285+
);
266286
}
267287
} else {
268288
throw new IllegalArgumentException("Unknown token [" + token + "] in alias [" + alias.name + "]");

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,21 @@ 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+
32+
private static final NodeFeature THROW_EXCEPTION_ON_INDEX_CREATION_IF_UNSUPPORTED_VALUE_TYPE_IN_ALIAS = new NodeFeature(
33+
"index.throw_exception_on_index_creation_if_unsupported_value_type_in_alias"
34+
);
35+
2836
@Override
2937
public Set<NodeFeature> getTestFeatures() {
30-
return Set.of(LOGSDB_NO_HOST_NAME_FIELD, SYNONYMS_SET_LENIENT_ON_NON_EXISTING);
38+
return Set.of(
39+
LOGSDB_NO_HOST_NAME_FIELD,
40+
SYNONYMS_SET_LENIENT_ON_NON_EXISTING,
41+
THROW_EXCEPTION_FOR_UNKNOWN_TOKEN_IN_REST_INDEX_PUT_ALIAS_ACTION,
42+
THROW_EXCEPTION_ON_INDEX_CREATION_IF_UNSUPPORTED_VALUE_TYPE_IN_ALIAS
43+
);
3144
}
3245
}

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 1 deletion
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
}

test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@
193193
import java.util.Arrays;
194194
import java.util.Collection;
195195
import java.util.Collections;
196+
import java.util.HashMap;
196197
import java.util.HashSet;
197198
import java.util.IdentityHashMap;
198199
import java.util.List;
@@ -1207,6 +1208,19 @@ public static String getNodeId(String nodeName) {
12071208
return internalCluster().getInstance(ClusterService.class, nodeName).localNode().getId();
12081209
}
12091210

1211+
/**
1212+
* @return A map of the cluster node Ids to their node names.
1213+
*/
1214+
public static Map<String, String> nodeIdsToNames() {
1215+
var names = internalCluster().getNodeNames();
1216+
Map<String, String> nodeIdsToNames = new HashMap<>();
1217+
for (var name : names) {
1218+
nodeIdsToNames.put(getNodeId(name), name);
1219+
}
1220+
return nodeIdsToNames;
1221+
1222+
}
1223+
12101224
/**
12111225
* Waits until at least a give number of document is visible for searchers
12121226
*

0 commit comments

Comments
 (0)