Skip to content

Commit ec04366

Browse files
committed
Merge branch 'master' into ccr
* master: Add get stored script and delete stored script to high level REST API - post backport fix Add get stored script and delete stored script to high level REST API (#31355) Core: Combine Action and GenericAction (#31405) Fix reference to XContentBuilder.string() (#31337) Avoid sending duplicate remote failed shard requests (#31313) Fix defaults in GeoShapeFieldMapper output (#31302) RestAPI: Reject forcemerge requests with a body (#30792) Packaging: Remove windows bin files from the tar distribution (#30596) Docs: Use the default distribution to test docs (#31251) [DOCS] Adds testing for security APIs (#31345) Clarify that IP range data can be specified in CIDR notation. (#31374) Use system context for cluster state update tasks (#31241) Percentile/Ranks should return null instead of NaN when empty (#30460) REST high-level client: add validate query API (#31077) Move language analyzers from server to analysis-common module. (#31300) [Test] Fix :example-plugins:rest-handler on Windows Expose lucene's RemoveDuplicatesTokenFilter (#31275) Reload secure settings for plugins (#31383) Remove some cases in FieldTypeLookupTests that are no longer relevant. (#31381) Ensure we don't use a remote profile if cluster name matches (#31331) [TEST] Double write alias fault (#30942) [DOCS] Fix version in SQL JDBC Maven template [DOCS] Improve install and setup section for SQL JDBC SQL: Fix rest endpoint names in node stats (#31371) Support for remote path in reindex api - post backport fix Closes #22913 [ML] Put ML filter API response should contain the filter (#31362) Support for remote path in reindex api (#31290) Add byte array pooling to nio http transport (#31349) Remove trial status info from start trial doc (#31365) [DOCS] Adds links to release notes and highlights add is-write-index flag to aliases (#30942) Add rollover-creation-date setting to rolled over index (#31144) [ML] Hold ML filter items in sorted set (#31338) [Tests] Fix edge case in ScriptedMetricAggregatorTests (#31357)
2 parents 50ce990 + 2396cbd commit ec04366

File tree

518 files changed

+8560
-2404
lines changed

Some content is hidden

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

518 files changed

+8560
-2404
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/DocsTestPlugin.groovy

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public class DocsTestPlugin extends RestTestPlugin {
3232
public void apply(Project project) {
3333
project.pluginManager.apply('elasticsearch.standalone-rest-test')
3434
super.apply(project)
35+
// The distribution can be configured with -Dtests.distribution on the command line
36+
project.integTestCluster.distribution = System.getProperty('tests.distribution', 'zip')
3537
// Docs are published separately so no need to assemble
3638
project.tasks.remove(project.assemble)
3739
project.build.dependsOn.remove('assemble')
@@ -43,6 +45,8 @@ public class DocsTestPlugin extends RestTestPlugin {
4345
'\\{version\\}':
4446
VersionProperties.elasticsearch.toString().replace('-SNAPSHOT', ''),
4547
'\\{lucene_version\\}' : VersionProperties.lucene.replaceAll('-snapshot-\\w+$', ''),
48+
'\\{build_flavor\\}' :
49+
project.integTestCluster.distribution.startsWith('oss-') ? 'oss' : 'default',
4650
]
4751
Task listSnippets = project.tasks.create('listSnippets', SnippetsTask)
4852
listSnippets.group 'Docs'

client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/bulk/NoopBulkAction.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
package org.elasticsearch.plugin.noop.action.bulk;
2020

2121
import org.elasticsearch.action.Action;
22-
import org.elasticsearch.action.bulk.BulkRequest;
2322
import org.elasticsearch.action.bulk.BulkResponse;
2423

25-
public class NoopBulkAction extends Action<BulkRequest, BulkResponse> {
24+
public class NoopBulkAction extends Action<BulkResponse> {
2625
public static final String NAME = "mock:data/write/bulk";
2726

2827
public static final NoopBulkAction INSTANCE = new NoopBulkAction();

client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/search/NoopSearchAction.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
package org.elasticsearch.plugin.noop.action.search;
2020

2121
import org.elasticsearch.action.Action;
22-
import org.elasticsearch.action.search.SearchRequest;
2322
import org.elasticsearch.action.search.SearchResponse;
2423

25-
public class NoopSearchAction extends Action<SearchRequest, SearchResponse> {
24+
public class NoopSearchAction extends Action<SearchResponse> {
2625
public static final NoopSearchAction INSTANCE = new NoopSearchAction();
2726
public static final String NAME = "mock:data/read/search";
2827

client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java

+32
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse;
5858
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
5959
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse;
60+
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
61+
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse;
6062
import org.elasticsearch.rest.RestStatus;
6163

6264
import java.io.IOException;
@@ -661,6 +663,36 @@ public void putTemplateAsync(PutIndexTemplateRequest putIndexTemplateRequest, Re
661663
PutIndexTemplateResponse::fromXContent, listener, emptySet());
662664
}
663665

666+
/**
667+
* Validate a potentially expensive query without executing it.
668+
* <p>
669+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-validate.html"> Validate Query API
670+
* on elastic.co</a>
671+
* @param validateQueryRequest the request
672+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
673+
* @return the response
674+
* @throws IOException in case there is a problem sending the request or parsing back the response
675+
*/
676+
public ValidateQueryResponse validateQuery(ValidateQueryRequest validateQueryRequest, RequestOptions options) throws IOException {
677+
return restHighLevelClient.performRequestAndParseEntity(validateQueryRequest, RequestConverters::validateQuery, options,
678+
ValidateQueryResponse::fromXContent, emptySet());
679+
}
680+
681+
/**
682+
* Asynchronously validate a potentially expensive query without executing it.
683+
* <p>
684+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-validate.html"> Validate Query API
685+
* on elastic.co</a>
686+
* @param validateQueryRequest the request
687+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
688+
* @param listener the listener to be notified upon request completion
689+
*/
690+
public void validateQueryAsync(ValidateQueryRequest validateQueryRequest, RequestOptions options,
691+
ActionListener<ValidateQueryResponse> listener) {
692+
restHighLevelClient.performRequestAsyncAndParseEntity(validateQueryRequest, RequestConverters::validateQuery, options,
693+
ValidateQueryResponse::fromXContent, listener, emptySet());
694+
}
695+
664696
/**
665697
* Gets index templates using the Index Templates API
666698
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API

client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java

+34
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest;
3838
import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest;
3939
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
40+
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest;
41+
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest;
4042
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
4143
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
4244
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest;
@@ -58,6 +60,7 @@
5860
import org.elasticsearch.action.admin.indices.shrink.ResizeType;
5961
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest;
6062
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
63+
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
6164
import org.elasticsearch.action.bulk.BulkRequest;
6265
import org.elasticsearch.action.delete.DeleteRequest;
6366
import org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest;
@@ -856,6 +859,20 @@ static Request putTemplate(PutIndexTemplateRequest putIndexTemplateRequest) thro
856859
return request;
857860
}
858861

862+
static Request validateQuery(ValidateQueryRequest validateQueryRequest) throws IOException {
863+
String[] indices = validateQueryRequest.indices() == null ? Strings.EMPTY_ARRAY : validateQueryRequest.indices();
864+
String[] types = validateQueryRequest.types() == null || indices.length <= 0 ? Strings.EMPTY_ARRAY : validateQueryRequest.types();
865+
String endpoint = endpoint(indices, types, "_validate/query");
866+
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
867+
Params params = new Params(request);
868+
params.withIndicesOptions(validateQueryRequest.indicesOptions());
869+
params.putParam("explain", Boolean.toString(validateQueryRequest.explain()));
870+
params.putParam("all_shards", Boolean.toString(validateQueryRequest.allShards()));
871+
params.putParam("rewrite", Boolean.toString(validateQueryRequest.rewrite()));
872+
request.setEntity(createEntity(validateQueryRequest, REQUEST_BODY_CONTENT_TYPE));
873+
return request;
874+
}
875+
859876
static Request getAlias(GetAliasesRequest getAliasesRequest) {
860877
String[] indices = getAliasesRequest.indices() == null ? Strings.EMPTY_ARRAY : getAliasesRequest.indices();
861878
String[] aliases = getAliasesRequest.aliases() == null ? Strings.EMPTY_ARRAY : getAliasesRequest.aliases();
@@ -877,6 +894,23 @@ static Request getTemplates(GetIndexTemplatesRequest getIndexTemplatesRequest) t
877894
return request;
878895
}
879896

897+
static Request getScript(GetStoredScriptRequest getStoredScriptRequest) {
898+
String endpoint = new EndpointBuilder().addPathPartAsIs("_scripts").addPathPart(getStoredScriptRequest.id()).build();
899+
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
900+
Params params = new Params(request);
901+
params.withMasterTimeout(getStoredScriptRequest.masterNodeTimeout());
902+
return request;
903+
}
904+
905+
static Request deleteScript(DeleteStoredScriptRequest deleteStoredScriptRequest) {
906+
String endpoint = new EndpointBuilder().addPathPartAsIs("_scripts").addPathPart(deleteStoredScriptRequest.id()).build();
907+
Request request = new Request(HttpDelete.METHOD_NAME, endpoint);
908+
Params params = new Params(request);
909+
params.withTimeout(deleteStoredScriptRequest.timeout());
910+
params.withMasterTimeout(deleteStoredScriptRequest.masterNodeTimeout());
911+
return request;
912+
}
913+
880914
private static HttpEntity createEntity(ToXContent toXContent, XContentType xContentType) throws IOException {
881915
BytesRef source = XContentHelper.toXContent(toXContent, xContentType, false).toBytesRef();
882916
return new ByteArrayEntity(source.bytes, source.offset, source.length, createContentType(xContentType));

client/rest-high-level/src/main/java/org/elasticsearch/client/RestHighLevelClient.java

+60
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
import org.elasticsearch.action.ActionListener;
2727
import org.elasticsearch.action.ActionRequest;
2828
import org.elasticsearch.action.ActionRequestValidationException;
29+
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest;
30+
import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptResponse;
31+
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest;
32+
import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptResponse;
2933
import org.elasticsearch.action.bulk.BulkRequest;
3034
import org.elasticsearch.action.bulk.BulkResponse;
3135
import org.elasticsearch.action.delete.DeleteRequest;
@@ -652,6 +656,62 @@ public final FieldCapabilitiesResponse fieldCaps(FieldCapabilitiesRequest fieldC
652656
FieldCapabilitiesResponse::fromXContent, emptySet());
653657
}
654658

659+
/**
660+
* Get stored script by id.
661+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-using.html">
662+
* How to use scripts on elastic.co</a>
663+
* @param request the request
664+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
665+
* @return the response
666+
* @throws IOException in case there is a problem sending the request or parsing back the response
667+
*/
668+
public GetStoredScriptResponse getScript(GetStoredScriptRequest request, RequestOptions options) throws IOException {
669+
return performRequestAndParseEntity(request, RequestConverters::getScript, options,
670+
GetStoredScriptResponse::fromXContent, emptySet());
671+
}
672+
673+
/**
674+
* Asynchronously get stored script by id.
675+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-using.html">
676+
* How to use scripts on elastic.co</a>
677+
* @param request the request
678+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
679+
* @param listener the listener to be notified upon request completion
680+
*/
681+
public void getScriptAsync(GetStoredScriptRequest request, RequestOptions options,
682+
ActionListener<GetStoredScriptResponse> listener) {
683+
performRequestAsyncAndParseEntity(request, RequestConverters::getScript, options,
684+
GetStoredScriptResponse::fromXContent, listener, emptySet());
685+
}
686+
687+
/**
688+
* Delete stored script by id.
689+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-using.html">
690+
* How to use scripts on elastic.co</a>
691+
* @param request the request
692+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
693+
* @return the response
694+
* @throws IOException in case there is a problem sending the request or parsing back the response
695+
*/
696+
public DeleteStoredScriptResponse deleteScript(DeleteStoredScriptRequest request, RequestOptions options) throws IOException {
697+
return performRequestAndParseEntity(request, RequestConverters::deleteScript, options,
698+
DeleteStoredScriptResponse::fromXContent, emptySet());
699+
}
700+
701+
/**
702+
* Asynchronously delete stored script by id.
703+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-using.html">
704+
* How to use scripts on elastic.co</a>
705+
* @param request the request
706+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
707+
* @param listener the listener to be notified upon request completion
708+
*/
709+
public void deleteScriptAsync(DeleteStoredScriptRequest request, RequestOptions options,
710+
ActionListener<DeleteStoredScriptResponse> listener) {
711+
performRequestAsyncAndParseEntity(request, RequestConverters::deleteScript, options,
712+
DeleteStoredScriptResponse::fromXContent, listener, emptySet());
713+
}
714+
655715
/**
656716
* Asynchronously executes a request using the Field Capabilities API.
657717
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-field-caps.html">Field Capabilities API

client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java

+39
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.elasticsearch.client;
2121

2222
import org.apache.http.client.methods.HttpGet;
23+
import org.apache.http.client.methods.HttpPost;
2324
import org.apache.http.client.methods.HttpPut;
2425
import org.elasticsearch.ElasticsearchException;
2526
import org.elasticsearch.ElasticsearchStatusException;
@@ -63,6 +64,8 @@
6364
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse;
6465
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
6566
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse;
67+
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
68+
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse;
6669
import org.elasticsearch.action.index.IndexRequest;
6770
import org.elasticsearch.action.support.IndicesOptions;
6871
import org.elasticsearch.action.support.WriteRequest;
@@ -80,6 +83,8 @@
8083
import org.elasticsearch.common.xcontent.json.JsonXContent;
8184
import org.elasticsearch.common.xcontent.support.XContentMapValues;
8285
import org.elasticsearch.index.IndexSettings;
86+
import org.elasticsearch.index.query.QueryBuilder;
87+
import org.elasticsearch.index.query.QueryBuilders;
8388
import org.elasticsearch.rest.RestStatus;
8489

8590
import java.io.IOException;
@@ -1155,6 +1160,40 @@ public void testPutTemplateBadRequests() throws Exception {
11551160
assertThat(unknownSettingError.getDetailedMessage(), containsString("unknown setting [index.this-setting-does-not-exist]"));
11561161
}
11571162

1163+
public void testValidateQuery() throws IOException{
1164+
String index = "some_index";
1165+
createIndex(index, Settings.EMPTY);
1166+
QueryBuilder builder = QueryBuilders
1167+
.boolQuery()
1168+
.must(QueryBuilders.queryStringQuery("*:*"))
1169+
.filter(QueryBuilders.termQuery("user", "kimchy"));
1170+
ValidateQueryRequest request = new ValidateQueryRequest(index).query(builder);
1171+
request.explain(randomBoolean());
1172+
ValidateQueryResponse response = execute(request, highLevelClient().indices()::validateQuery,
1173+
highLevelClient().indices()::validateQueryAsync);
1174+
assertTrue(response.isValid());
1175+
}
1176+
1177+
public void testInvalidValidateQuery() throws IOException{
1178+
String index = "shakespeare";
1179+
1180+
createIndex(index, Settings.EMPTY);
1181+
Request postDoc = new Request(HttpPost.METHOD_NAME, "/" + index + "/1");
1182+
postDoc.setJsonEntity(
1183+
"{\"type\":\"act\",\"line_id\":1,\"play_name\":\"Henry IV\", \"speech_number\":\"\"," +
1184+
"\"line_number\":\"\",\"speaker\":\"\",\"text_entry\":\"ACT I\"}");
1185+
assertOK(client().performRequest(postDoc));
1186+
1187+
QueryBuilder builder = QueryBuilders
1188+
.queryStringQuery("line_id:foo")
1189+
.lenient(false);
1190+
ValidateQueryRequest request = new ValidateQueryRequest(index).query(builder);
1191+
request.explain(true);
1192+
ValidateQueryResponse response = execute(request, highLevelClient().indices()::validateQuery,
1193+
highLevelClient().indices()::validateQueryAsync);
1194+
assertFalse(response.isValid());
1195+
}
1196+
11581197
public void testGetIndexTemplate() throws Exception {
11591198
RestHighLevelClient client = highLevelClient();
11601199

0 commit comments

Comments
 (0)