Skip to content

Commit 35243f2

Browse files
committed
Merge branch '6.x' into ccr-6.x
* 6.x: Add get stored script and delete stored script to high level REST API Increasing skip version for failing test on 6.x Skip get_alias tests for 5.x (#31397) Fix defaults in GeoShapeFieldMapper output (#31302) Test: better error message on failure Mute DefaultShardsIT#testDefaultShards test Fix reference to XContentBuilder.string() (#31337) [DOCS] Adds monitoring breaking change (#31369) [DOCS] Adds security breaking change (#31375) [DOCS] Backports breaking change (#31373) RestAPI: Reject forcemerge requests with a body (#30792) Docs: Use the default distribution to test docs (#31251) Use system context for cluster state update tasks (#31241) [DOCS] Adds testing for security APIs (#31345) [DOCS] Removes ML item from release highlights [DOCS] Removes breaking change (#31376) REST high-level client: add validate query API (#31077) Move language analyzers from server to analysis-common module. (#31300) Expose lucene's RemoveDuplicatesTokenFilter (#31275) [Test] Fix :example-plugins:rest-handler on Windows Delete typos in SAML docs (#31199) Ensure we don't use a remote profile if cluster name matches (#31331) Test: Skip alias tests that failed all weekend [DOCS] Fix version in SQL JDBC Maven template [DOCS] Improve install and setup section for SQL JDBC Add ingest-attachment support for per document `indexed_chars` limit (#31352) SQL: Fix rest endpoint names in node stats (#31371) [DOCS] Fixes small issue in release notes Support for remote path in reindex api Closes #22913 [ML] Put ML filter API response should contain the filter (#31362) Remove trial status info from start trial doc (#31365) [DOCS] Added links in breaking changes pages [DOCS] Adds links to release notes and highlights Docs: Document changes in rest client QA: Fix tribe tests to use node selector REST Client: NodeSelector for node attributes (#31296) LLClient: Fix assertion on windows LLClient: Support host selection (#30523) Add QA project and fixture based test for discovery-ec2 plugin (#31107) [ML] Hold ML filter items in sorted set (#31338) [ML] Add description to ML filters (#31330)
2 parents aa0b957 + 70c14a5 commit 35243f2

File tree

215 files changed

+7136
-1535
lines changed

Some content is hidden

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

215 files changed

+7136
-1535
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/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java

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

6365
import java.io.IOException;
@@ -1091,6 +1093,36 @@ public void putTemplateAsync(PutIndexTemplateRequest putIndexTemplateRequest, Re
10911093
PutIndexTemplateResponse::fromXContent, listener, emptySet());
10921094
}
10931095

1096+
/**
1097+
* Validate a potentially expensive query without executing it.
1098+
* <p>
1099+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-validate.html"> Validate Query API
1100+
* on elastic.co</a>
1101+
* @param validateQueryRequest the request
1102+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
1103+
* @return the response
1104+
* @throws IOException in case there is a problem sending the request or parsing back the response
1105+
*/
1106+
public ValidateQueryResponse validateQuery(ValidateQueryRequest validateQueryRequest, RequestOptions options) throws IOException {
1107+
return restHighLevelClient.performRequestAndParseEntity(validateQueryRequest, RequestConverters::validateQuery, options,
1108+
ValidateQueryResponse::fromXContent, emptySet());
1109+
}
1110+
1111+
/**
1112+
* Asynchronously validate a potentially expensive query without executing it.
1113+
* <p>
1114+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-validate.html"> Validate Query API
1115+
* on elastic.co</a>
1116+
* @param validateQueryRequest the request
1117+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
1118+
* @param listener the listener to be notified upon request completion
1119+
*/
1120+
public void validateQueryAsync(ValidateQueryRequest validateQueryRequest, RequestOptions options,
1121+
ActionListener<ValidateQueryResponse> listener) {
1122+
restHighLevelClient.performRequestAsyncAndParseEntity(validateQueryRequest, RequestConverters::validateQuery, options,
1123+
ValidateQueryResponse::fromXContent, listener, emptySet());
1124+
}
1125+
10941126
/**
10951127
* Gets index templates using the Index Templates API
10961128
* 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;
@@ -877,6 +880,20 @@ static Request getTemplates(GetIndexTemplatesRequest getIndexTemplatesRequest) t
877880
return request;
878881
}
879882

883+
static Request validateQuery(ValidateQueryRequest validateQueryRequest) throws IOException {
884+
String[] indices = validateQueryRequest.indices() == null ? Strings.EMPTY_ARRAY : validateQueryRequest.indices();
885+
String[] types = validateQueryRequest.types() == null || indices.length <= 0 ? Strings.EMPTY_ARRAY : validateQueryRequest.types();
886+
String endpoint = endpoint(indices, types, "_validate/query");
887+
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
888+
Params params = new Params(request);
889+
params.withIndicesOptions(validateQueryRequest.indicesOptions());
890+
params.putParam("explain", Boolean.toString(validateQueryRequest.explain()));
891+
params.putParam("all_shards", Boolean.toString(validateQueryRequest.allShards()));
892+
params.putParam("rewrite", Boolean.toString(validateQueryRequest.rewrite()));
893+
request.setEntity(createEntity(validateQueryRequest, REQUEST_BODY_CONTENT_TYPE));
894+
return request;
895+
}
896+
880897
static Request getAlias(GetAliasesRequest getAliasesRequest) {
881898
String[] indices = getAliasesRequest.indices() == null ? Strings.EMPTY_ARRAY : getAliasesRequest.indices();
882899
String[] aliases = getAliasesRequest.aliases() == null ? Strings.EMPTY_ARRAY : getAliasesRequest.aliases();
@@ -888,6 +905,23 @@ static Request getAlias(GetAliasesRequest getAliasesRequest) {
888905
return request;
889906
}
890907

908+
static Request getScript(GetStoredScriptRequest getStoredScriptRequest) {
909+
String endpoint = new EndpointBuilder().addPathPartAsIs("_scripts").addPathPart(getStoredScriptRequest.id()).build();
910+
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
911+
Params params = new Params(request);
912+
params.withMasterTimeout(getStoredScriptRequest.masterNodeTimeout());
913+
return request;
914+
}
915+
916+
static Request deleteScript(DeleteStoredScriptRequest deleteStoredScriptRequest) {
917+
String endpoint = new EndpointBuilder().addPathPartAsIs("_scripts").addPathPart(deleteStoredScriptRequest.id()).build();
918+
Request request = new Request(HttpDelete.METHOD_NAME, endpoint);
919+
Params params = new Params(request);
920+
params.withTimeout(deleteStoredScriptRequest.timeout());
921+
params.withMasterTimeout(deleteStoredScriptRequest.masterNodeTimeout());
922+
return request;
923+
}
924+
891925
private static HttpEntity createEntity(ToXContent toXContent, XContentType xContentType) throws IOException {
892926
BytesRef source = XContentHelper.toXContent(toXContent, xContentType, false).toBytesRef();
893927
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;
@@ -963,6 +967,62 @@ public final FieldCapabilitiesResponse fieldCaps(FieldCapabilitiesRequest fieldC
963967
FieldCapabilitiesResponse::fromXContent, emptySet());
964968
}
965969

970+
/**
971+
* Get stored script by id.
972+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-using.html">
973+
* How to use scripts on elastic.co</a>
974+
* @param request the request
975+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
976+
* @return the response
977+
* @throws IOException in case there is a problem sending the request or parsing back the response
978+
*/
979+
public GetStoredScriptResponse getScript(GetStoredScriptRequest request, RequestOptions options) throws IOException {
980+
return performRequestAndParseEntity(request, RequestConverters::getScript, options,
981+
GetStoredScriptResponse::fromXContent, emptySet());
982+
}
983+
984+
/**
985+
* Asynchronously get stored script by id.
986+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-using.html">
987+
* How to use scripts on elastic.co</a>
988+
* @param request the request
989+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
990+
* @param listener the listener to be notified upon request completion
991+
*/
992+
public void getScriptAsync(GetStoredScriptRequest request, RequestOptions options,
993+
ActionListener<GetStoredScriptResponse> listener) {
994+
performRequestAsyncAndParseEntity(request, RequestConverters::getScript, options,
995+
GetStoredScriptResponse::fromXContent, listener, emptySet());
996+
}
997+
998+
/**
999+
* Delete stored script by id.
1000+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-using.html">
1001+
* How to use scripts on elastic.co</a>
1002+
* @param request the request
1003+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
1004+
* @return the response
1005+
* @throws IOException in case there is a problem sending the request or parsing back the response
1006+
*/
1007+
public DeleteStoredScriptResponse deleteScript(DeleteStoredScriptRequest request, RequestOptions options) throws IOException {
1008+
return performRequestAndParseEntity(request, RequestConverters::deleteScript, options,
1009+
DeleteStoredScriptResponse::fromXContent, emptySet());
1010+
}
1011+
1012+
/**
1013+
* Asynchronously delete stored script by id.
1014+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-using.html">
1015+
* How to use scripts on elastic.co</a>
1016+
* @param request the request
1017+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
1018+
* @param listener the listener to be notified upon request completion
1019+
*/
1020+
public void deleteScriptAsync(DeleteStoredScriptRequest request, RequestOptions options,
1021+
ActionListener<DeleteStoredScriptResponse> listener) {
1022+
performRequestAsyncAndParseEntity(request, RequestConverters::deleteScript, options,
1023+
DeleteStoredScriptResponse::fromXContent, listener, emptySet());
1024+
}
1025+
9661026
/**
9671027
* Asynchronously executes a request using the Field Capabilities API.
9681028
* 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;
@@ -64,6 +65,8 @@
6465
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse;
6566
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
6667
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse;
68+
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
69+
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse;
6770
import org.elasticsearch.action.index.IndexRequest;
6871
import org.elasticsearch.action.support.IndicesOptions;
6972
import org.elasticsearch.action.support.WriteRequest;
@@ -81,6 +84,8 @@
8184
import org.elasticsearch.common.xcontent.json.JsonXContent;
8285
import org.elasticsearch.common.xcontent.support.XContentMapValues;
8386
import org.elasticsearch.index.IndexSettings;
87+
import org.elasticsearch.index.query.QueryBuilder;
88+
import org.elasticsearch.index.query.QueryBuilders;
8489
import org.elasticsearch.rest.RestStatus;
8590

8691
import java.io.IOException;
@@ -1197,6 +1202,40 @@ public void testPutTemplateBadRequests() throws Exception {
11971202
assertThat(unknownSettingError.getDetailedMessage(), containsString("unknown setting [index.this-setting-does-not-exist]"));
11981203
}
11991204

1205+
public void testValidateQuery() throws IOException{
1206+
String index = "some_index";
1207+
createIndex(index, Settings.EMPTY);
1208+
QueryBuilder builder = QueryBuilders
1209+
.boolQuery()
1210+
.must(QueryBuilders.queryStringQuery("*:*"))
1211+
.filter(QueryBuilders.termQuery("user", "kimchy"));
1212+
ValidateQueryRequest request = new ValidateQueryRequest(index).query(builder);
1213+
request.explain(randomBoolean());
1214+
ValidateQueryResponse response = execute(request, highLevelClient().indices()::validateQuery,
1215+
highLevelClient().indices()::validateQueryAsync);
1216+
assertTrue(response.isValid());
1217+
}
1218+
1219+
public void testInvalidValidateQuery() throws IOException{
1220+
String index = "shakespeare";
1221+
1222+
createIndex(index, Settings.EMPTY);
1223+
Request postDoc = new Request(HttpPost.METHOD_NAME, "/" + index + "/1");
1224+
postDoc.setJsonEntity(
1225+
"{\"type\":\"act\",\"line_id\":1,\"play_name\":\"Henry IV\", \"speech_number\":\"\"," +
1226+
"\"line_number\":\"\",\"speaker\":\"\",\"text_entry\":\"ACT I\"}");
1227+
assertOK(client().performRequest(postDoc));
1228+
1229+
QueryBuilder builder = QueryBuilders
1230+
.queryStringQuery("line_id:foo")
1231+
.lenient(false);
1232+
ValidateQueryRequest request = new ValidateQueryRequest(index).query(builder);
1233+
request.explain(true);
1234+
ValidateQueryResponse response = execute(request, highLevelClient().indices()::validateQuery,
1235+
highLevelClient().indices()::validateQueryAsync);
1236+
assertFalse(response.isValid());
1237+
}
1238+
12001239
public void testGetIndexTemplate() throws Exception {
12011240
RestHighLevelClient client = highLevelClient();
12021241

0 commit comments

Comments
 (0)