Switch high level rest tests to new style requests (#31937)
In #29623 we added `Request` object flavored requests to the low level REST client and in #30315 we deprecated the old `performRequest`s. This changes all calls in the `client/rest-high-level` project to use the new versions.
This commit is contained in:
parent
d268b494d7
commit
aa6a1c5ca0
|
@ -612,7 +612,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
createIndex(index, Settings.EMPTY);
|
||||
closeIndex(index);
|
||||
ResponseException exception = expectThrows(ResponseException.class,
|
||||
() -> client().performRequest(HttpGet.METHOD_NAME, index + "/_search"));
|
||||
() -> client().performRequest(new Request(HttpGet.METHOD_NAME, index + "/_search")));
|
||||
assertThat(exception.getResponse().getStatusLine().getStatusCode(), equalTo(RestStatus.BAD_REQUEST.getStatus()));
|
||||
assertThat(exception.getMessage().contains(index), equalTo(true));
|
||||
|
||||
|
@ -621,7 +621,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
highLevelClient().indices()::openAsync);
|
||||
assertTrue(openIndexResponse.isAcknowledged());
|
||||
|
||||
Response response = client().performRequest(HttpGet.METHOD_NAME, index + "/_search");
|
||||
Response response = client().performRequest(new Request(HttpGet.METHOD_NAME, index + "/_search"));
|
||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus()));
|
||||
}
|
||||
|
||||
|
@ -650,7 +650,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
public void testCloseExistingIndex() throws IOException {
|
||||
String index = "index";
|
||||
createIndex(index, Settings.EMPTY);
|
||||
Response response = client().performRequest(HttpGet.METHOD_NAME, index + "/_search");
|
||||
Response response = client().performRequest(new Request(HttpGet.METHOD_NAME, index + "/_search"));
|
||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus()));
|
||||
|
||||
CloseIndexRequest closeIndexRequest = new CloseIndexRequest(index);
|
||||
|
@ -659,7 +659,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
assertTrue(closeIndexResponse.isAcknowledged());
|
||||
|
||||
ResponseException exception = expectThrows(ResponseException.class,
|
||||
() -> client().performRequest(HttpGet.METHOD_NAME, index + "/_search"));
|
||||
() -> client().performRequest(new Request(HttpGet.METHOD_NAME, index + "/_search")));
|
||||
assertThat(exception.getResponse().getStatusLine().getStatusCode(), equalTo(RestStatus.BAD_REQUEST.getStatus()));
|
||||
assertThat(exception.getMessage().contains(index), equalTo(true));
|
||||
}
|
||||
|
@ -817,7 +817,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
assertFalse(execute(getAliasesRequest, highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync));
|
||||
|
||||
createIndex("index", Settings.EMPTY);
|
||||
client().performRequest(HttpPut.METHOD_NAME, "/index/_alias/alias");
|
||||
client().performRequest(new Request(HttpPut.METHOD_NAME, "/index/_alias/alias"));
|
||||
assertTrue(execute(getAliasesRequest, highLevelClient().indices()::existsAlias, highLevelClient().indices()::existsAliasAsync));
|
||||
|
||||
GetAliasesRequest getAliasesRequest2 = new GetAliasesRequest();
|
||||
|
@ -936,10 +936,10 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
public void testGetAlias() throws IOException {
|
||||
{
|
||||
createIndex("index1", Settings.EMPTY);
|
||||
client().performRequest(HttpPut.METHOD_NAME, "/index1/_alias/alias1");
|
||||
client().performRequest(new Request(HttpPut.METHOD_NAME, "/index1/_alias/alias1"));
|
||||
|
||||
createIndex("index2", Settings.EMPTY);
|
||||
client().performRequest(HttpPut.METHOD_NAME, "/index2/_alias/alias2");
|
||||
client().performRequest(new Request(HttpPut.METHOD_NAME, "/index2/_alias/alias2"));
|
||||
|
||||
createIndex("index3", Settings.EMPTY);
|
||||
}
|
||||
|
@ -1075,7 +1075,7 @@ public class IndicesClientIT extends ESRestHighLevelClientTestCase {
|
|||
assertThat(getAliasesResponse.getError(), equalTo("alias [" + alias + "] missing"));
|
||||
}
|
||||
createIndex(index, Settings.EMPTY);
|
||||
client().performRequest(HttpPut.METHOD_NAME, index + "/_alias/" + alias);
|
||||
client().performRequest(new Request(HttpPut.METHOD_NAME, index + "/_alias/" + alias));
|
||||
{
|
||||
GetAliasesRequest getAliasesRequest = new GetAliasesRequest().indices(index, "non_existent_index");
|
||||
GetAliasesResponse getAliasesResponse = execute(getAliasesRequest, highLevelClient().indices()::getAlias,
|
||||
|
|
|
@ -39,7 +39,7 @@ public class PingAndInfoIT extends ESRestHighLevelClientTestCase {
|
|||
public void testInfo() throws IOException {
|
||||
MainResponse info = highLevelClient().info(RequestOptions.DEFAULT);
|
||||
// compare with what the low level client outputs
|
||||
Map<String, Object> infoAsMap = entityAsMap(adminClient().performRequest(HttpGet.METHOD_NAME, "/"));
|
||||
Map<String, Object> infoAsMap = entityAsMap(adminClient().performRequest(new Request(HttpGet.METHOD_NAME, "/")));
|
||||
assertEquals(infoAsMap.get("cluster_name"), info.getClusterName().value());
|
||||
assertEquals(infoAsMap.get("cluster_uuid"), info.getClusterUuid());
|
||||
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
package org.elasticsearch.client;
|
||||
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.index.query.MatchAllQueryBuilder;
|
||||
|
@ -37,7 +35,6 @@ import org.junit.Before;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -49,19 +46,17 @@ public class RankEvalIT extends ESRestHighLevelClientTestCase {
|
|||
|
||||
@Before
|
||||
public void indexDocuments() throws IOException {
|
||||
StringEntity doc = new StringEntity("{\"text\":\"berlin\"}", ContentType.APPLICATION_JSON);
|
||||
client().performRequest("PUT", "/index/doc/1", Collections.emptyMap(), doc);
|
||||
doc = new StringEntity("{\"text\":\"amsterdam\"}", ContentType.APPLICATION_JSON);
|
||||
client().performRequest("PUT", "/index/doc/2", Collections.emptyMap(), doc);
|
||||
client().performRequest("PUT", "/index/doc/3", Collections.emptyMap(), doc);
|
||||
client().performRequest("PUT", "/index/doc/4", Collections.emptyMap(), doc);
|
||||
client().performRequest("PUT", "/index/doc/5", Collections.emptyMap(), doc);
|
||||
client().performRequest("PUT", "/index/doc/6", Collections.emptyMap(), doc);
|
||||
client().performRequest("POST", "/index/_refresh");
|
||||
|
||||
// add another index to test basic multi index support
|
||||
client().performRequest("PUT", "/index2/doc/7", Collections.emptyMap(), doc);
|
||||
client().performRequest("POST", "/index2/_refresh");
|
||||
Request berlin = new Request("PUT", "/index/doc/berlin");
|
||||
berlin.setJsonEntity("{\"text\":\"berlin\"}");
|
||||
client().performRequest(berlin);
|
||||
for (int i = 0; i < 6; i++) {
|
||||
// add another index to test basic multi index support
|
||||
String index = i == 0 ? "index2" : "index";
|
||||
Request amsterdam = new Request("PUT", "/" + index + "/doc/amsterdam" + i);
|
||||
amsterdam.setJsonEntity("{\"text\":\"amsterdam\"}");
|
||||
client().performRequest(amsterdam);
|
||||
}
|
||||
client().performRequest(new Request("POST", "/_refresh"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,10 +66,10 @@ public class RankEvalIT extends ESRestHighLevelClientTestCase {
|
|||
public void testRankEvalRequest() throws IOException {
|
||||
SearchSourceBuilder testQuery = new SearchSourceBuilder();
|
||||
testQuery.query(new MatchAllQueryBuilder());
|
||||
List<RatedDocument> amsterdamRatedDocs = createRelevant("index" , "2", "3", "4", "5");
|
||||
amsterdamRatedDocs.addAll(createRelevant("index2", "7"));
|
||||
List<RatedDocument> amsterdamRatedDocs = createRelevant("index" , "amsterdam1", "amsterdam2", "amsterdam3", "amsterdam4");
|
||||
amsterdamRatedDocs.addAll(createRelevant("index2", "amsterdam0"));
|
||||
RatedRequest amsterdamRequest = new RatedRequest("amsterdam_query", amsterdamRatedDocs, testQuery);
|
||||
RatedRequest berlinRequest = new RatedRequest("berlin_query", createRelevant("index", "1"), testQuery);
|
||||
RatedRequest berlinRequest = new RatedRequest("berlin_query", createRelevant("index", "berlin"), testQuery);
|
||||
List<RatedRequest> specifications = new ArrayList<>();
|
||||
specifications.add(amsterdamRequest);
|
||||
specifications.add(berlinRequest);
|
||||
|
@ -94,7 +89,7 @@ public class RankEvalIT extends ESRestHighLevelClientTestCase {
|
|||
assertEquals(7, hitsAndRatings.size());
|
||||
for (RatedSearchHit hit : hitsAndRatings) {
|
||||
String id = hit.getSearchHit().getId();
|
||||
if (id.equals("1") || id.equals("6")) {
|
||||
if (id.equals("berlin") || id.equals("amsterdam5")) {
|
||||
assertFalse(hit.getRating().isPresent());
|
||||
} else {
|
||||
assertEquals(1, hit.getRating().get().intValue());
|
||||
|
@ -106,7 +101,7 @@ public class RankEvalIT extends ESRestHighLevelClientTestCase {
|
|||
assertEquals(7, hitsAndRatings.size());
|
||||
for (RatedSearchHit hit : hitsAndRatings) {
|
||||
String id = hit.getSearchHit().getId();
|
||||
if (id.equals("1")) {
|
||||
if (id.equals("berlin")) {
|
||||
assertEquals(1, hit.getRating().get().intValue());
|
||||
} else {
|
||||
assertFalse(hit.getRating().isPresent());
|
||||
|
@ -114,7 +109,7 @@ public class RankEvalIT extends ESRestHighLevelClientTestCase {
|
|||
}
|
||||
|
||||
// now try this when test2 is closed
|
||||
client().performRequest("POST", "index2/_close", Collections.emptyMap());
|
||||
client().performRequest(new Request("POST", "index2/_close"));
|
||||
rankEvalRequest.indicesOptions(IndicesOptions.fromParameters(null, "true", null, SearchRequest.DEFAULT_INDICES_OPTIONS));
|
||||
response = execute(rankEvalRequest, highLevelClient()::rankEval, highLevelClient()::rankEvalAsync);
|
||||
}
|
||||
|
|
|
@ -19,12 +19,8 @@
|
|||
|
||||
package org.elasticsearch.client;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.nio.entity.NStringEntity;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.ElasticsearchStatusException;
|
||||
import org.elasticsearch.action.explain.ExplainRequest;
|
||||
|
@ -101,85 +97,106 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
|
||||
@Before
|
||||
public void indexDocuments() throws IOException {
|
||||
StringEntity doc1 = new StringEntity("{\"type\":\"type1\", \"num\":10, \"num2\":50}", ContentType.APPLICATION_JSON);
|
||||
client().performRequest(HttpPut.METHOD_NAME, "/index/type/1", Collections.emptyMap(), doc1);
|
||||
StringEntity doc2 = new StringEntity("{\"type\":\"type1\", \"num\":20, \"num2\":40}", ContentType.APPLICATION_JSON);
|
||||
client().performRequest(HttpPut.METHOD_NAME, "/index/type/2", Collections.emptyMap(), doc2);
|
||||
StringEntity doc3 = new StringEntity("{\"type\":\"type1\", \"num\":50, \"num2\":35}", ContentType.APPLICATION_JSON);
|
||||
client().performRequest(HttpPut.METHOD_NAME, "/index/type/3", Collections.emptyMap(), doc3);
|
||||
StringEntity doc4 = new StringEntity("{\"type\":\"type2\", \"num\":100, \"num2\":10}", ContentType.APPLICATION_JSON);
|
||||
client().performRequest(HttpPut.METHOD_NAME, "/index/type/4", Collections.emptyMap(), doc4);
|
||||
StringEntity doc5 = new StringEntity("{\"type\":\"type2\", \"num\":100, \"num2\":10}", ContentType.APPLICATION_JSON);
|
||||
client().performRequest(HttpPut.METHOD_NAME, "/index/type/5", Collections.emptyMap(), doc5);
|
||||
client().performRequest(HttpPost.METHOD_NAME, "/index/_refresh");
|
||||
{
|
||||
Request doc1 = new Request(HttpPut.METHOD_NAME, "/index/type/1");
|
||||
doc1.setJsonEntity("{\"type\":\"type1\", \"num\":10, \"num2\":50}");
|
||||
client().performRequest(doc1);
|
||||
Request doc2 = new Request(HttpPut.METHOD_NAME, "/index/type/2");
|
||||
doc2.setJsonEntity("{\"type\":\"type1\", \"num\":20, \"num2\":40}");
|
||||
client().performRequest(doc2);
|
||||
Request doc3 = new Request(HttpPut.METHOD_NAME, "/index/type/3");
|
||||
doc3.setJsonEntity("{\"type\":\"type1\", \"num\":50, \"num2\":35}");
|
||||
client().performRequest(doc3);
|
||||
Request doc4 = new Request(HttpPut.METHOD_NAME, "/index/type/4");
|
||||
doc4.setJsonEntity("{\"type\":\"type2\", \"num\":100, \"num2\":10}");
|
||||
client().performRequest(doc4);
|
||||
Request doc5 = new Request(HttpPut.METHOD_NAME, "/index/type/5");
|
||||
doc5.setJsonEntity("{\"type\":\"type2\", \"num\":100, \"num2\":10}");
|
||||
client().performRequest(doc5);
|
||||
}
|
||||
|
||||
{
|
||||
Request doc1 = new Request(HttpPut.METHOD_NAME, "/index1/doc/1");
|
||||
doc1.setJsonEntity("{\"field\":\"value1\", \"rating\": 7}");
|
||||
client().performRequest(doc1);
|
||||
Request doc2 = new Request(HttpPut.METHOD_NAME, "/index1/doc/2");
|
||||
doc2.setJsonEntity("{\"field\":\"value2\"}");
|
||||
client().performRequest(doc2);
|
||||
}
|
||||
|
||||
StringEntity doc = new StringEntity("{\"field\":\"value1\", \"rating\": 7}", ContentType.APPLICATION_JSON);
|
||||
client().performRequest(HttpPut.METHOD_NAME, "/index1/doc/1", Collections.emptyMap(), doc);
|
||||
doc = new StringEntity("{\"field\":\"value2\"}", ContentType.APPLICATION_JSON);
|
||||
client().performRequest(HttpPut.METHOD_NAME, "/index1/doc/2", Collections.emptyMap(), doc);
|
||||
|
||||
StringEntity mappings = new StringEntity(
|
||||
"{" +
|
||||
" \"mappings\": {" +
|
||||
" \"doc\": {" +
|
||||
" \"properties\": {" +
|
||||
" \"rating\": {" +
|
||||
" \"type\": \"keyword\"" +
|
||||
" }" +
|
||||
" }" +
|
||||
" }" +
|
||||
" }" +
|
||||
"}}",
|
||||
ContentType.APPLICATION_JSON);
|
||||
client().performRequest("PUT", "/index2", Collections.emptyMap(), mappings);
|
||||
doc = new StringEntity("{\"field\":\"value1\", \"rating\": \"good\"}", ContentType.APPLICATION_JSON);
|
||||
client().performRequest(HttpPut.METHOD_NAME, "/index2/doc/3", Collections.emptyMap(), doc);
|
||||
doc = new StringEntity("{\"field\":\"value2\"}", ContentType.APPLICATION_JSON);
|
||||
client().performRequest(HttpPut.METHOD_NAME, "/index2/doc/4", Collections.emptyMap(), doc);
|
||||
|
||||
doc = new StringEntity("{\"field\":\"value1\"}", ContentType.APPLICATION_JSON);
|
||||
client().performRequest(HttpPut.METHOD_NAME, "/index3/doc/5", Collections.emptyMap(), doc);
|
||||
doc = new StringEntity("{\"field\":\"value2\"}", ContentType.APPLICATION_JSON);
|
||||
client().performRequest(HttpPut.METHOD_NAME, "/index3/doc/6", Collections.emptyMap(), doc);
|
||||
|
||||
mappings = new StringEntity(
|
||||
"{" +
|
||||
{
|
||||
Request create = new Request("PUT", "/index2");
|
||||
create.setJsonEntity(
|
||||
"{" +
|
||||
" \"mappings\": {" +
|
||||
" \"doc\": {" +
|
||||
" \"properties\": {" +
|
||||
" \"field1\": {" +
|
||||
" \"type\": \"keyword\"," +
|
||||
" \"store\": true" +
|
||||
" }," +
|
||||
" \"field2\": {" +
|
||||
" \"type\": \"keyword\"," +
|
||||
" \"store\": true" +
|
||||
" \"rating\": {" +
|
||||
" \"type\": \"keyword\"" +
|
||||
" }" +
|
||||
" }" +
|
||||
" }" +
|
||||
" }" +
|
||||
"}}",
|
||||
ContentType.APPLICATION_JSON);
|
||||
client().performRequest(HttpPut.METHOD_NAME, "/index4", Collections.emptyMap(), mappings);
|
||||
doc = new StringEntity("{\"field1\":\"value1\", \"field2\":\"value2\"}", ContentType.APPLICATION_JSON);
|
||||
client().performRequest(HttpPut.METHOD_NAME, "/index4/doc/1", Collections.emptyMap(), doc);
|
||||
StringEntity aliasFilter = new StringEntity(
|
||||
"{" +
|
||||
" \"actions\" : [" +
|
||||
" {" +
|
||||
" \"add\" : {" +
|
||||
" \"index\" : \"index4\"," +
|
||||
" \"alias\" : \"alias4\"," +
|
||||
" \"filter\" : { \"term\" : { \"field2\" : \"value1\" } }" +
|
||||
" }" +
|
||||
" }" +
|
||||
" ]" +
|
||||
"}",
|
||||
ContentType.APPLICATION_JSON);
|
||||
client().performRequest(HttpPost.METHOD_NAME, "/_aliases", Collections.emptyMap(), aliasFilter);
|
||||
"}");
|
||||
client().performRequest(create);
|
||||
Request doc3 = new Request(HttpPut.METHOD_NAME, "/index2/doc/3");
|
||||
doc3.setJsonEntity("{\"field\":\"value1\", \"rating\": \"good\"}");
|
||||
client().performRequest(doc3);
|
||||
Request doc4 = new Request(HttpPut.METHOD_NAME, "/index2/doc/4");
|
||||
doc4.setJsonEntity("{\"field\":\"value2\"}");
|
||||
client().performRequest(doc4);
|
||||
}
|
||||
|
||||
client().performRequest(HttpPost.METHOD_NAME, "/index1,index2,index3,index4/_refresh");
|
||||
{
|
||||
Request doc5 = new Request(HttpPut.METHOD_NAME, "/index3/doc/5");
|
||||
doc5.setJsonEntity("{\"field\":\"value1\"}");
|
||||
client().performRequest(doc5);
|
||||
Request doc6 = new Request(HttpPut.METHOD_NAME, "/index3/doc/6");
|
||||
doc6.setJsonEntity("{\"field\":\"value2\"}");
|
||||
client().performRequest(doc6);
|
||||
}
|
||||
|
||||
{
|
||||
Request create = new Request(HttpPut.METHOD_NAME, "/index4");
|
||||
create.setJsonEntity(
|
||||
"{" +
|
||||
" \"mappings\": {" +
|
||||
" \"doc\": {" +
|
||||
" \"properties\": {" +
|
||||
" \"field1\": {" +
|
||||
" \"type\": \"keyword\"," +
|
||||
" \"store\": true" +
|
||||
" }," +
|
||||
" \"field2\": {" +
|
||||
" \"type\": \"keyword\"," +
|
||||
" \"store\": true" +
|
||||
" }" +
|
||||
" }" +
|
||||
" }" +
|
||||
" }" +
|
||||
"}");
|
||||
client().performRequest(create);
|
||||
Request doc1 = new Request(HttpPut.METHOD_NAME, "/index4/doc/1");
|
||||
doc1.setJsonEntity("{\"field1\":\"value1\", \"field2\":\"value2\"}");
|
||||
client().performRequest(doc1);
|
||||
|
||||
Request createFilteredAlias = new Request(HttpPost.METHOD_NAME, "/_aliases");
|
||||
createFilteredAlias.setJsonEntity(
|
||||
"{" +
|
||||
" \"actions\" : [" +
|
||||
" {" +
|
||||
" \"add\" : {" +
|
||||
" \"index\" : \"index4\"," +
|
||||
" \"alias\" : \"alias4\"," +
|
||||
" \"filter\" : { \"term\" : { \"field2\" : \"value1\" } }" +
|
||||
" }" +
|
||||
" }" +
|
||||
" ]" +
|
||||
"}");
|
||||
client().performRequest(createFilteredAlias);
|
||||
}
|
||||
|
||||
client().performRequest(new Request(HttpPost.METHOD_NAME, "/_refresh"));
|
||||
}
|
||||
|
||||
public void testSearchNoQuery() throws IOException {
|
||||
|
@ -377,7 +394,9 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
|
||||
public void testSearchWithParentJoin() throws IOException {
|
||||
final String indexName = "child_example";
|
||||
StringEntity parentMapping = new StringEntity("{\n" +
|
||||
Request createIndex = new Request(HttpPut.METHOD_NAME, "/" + indexName);
|
||||
createIndex.setJsonEntity(
|
||||
"{\n" +
|
||||
" \"mappings\": {\n" +
|
||||
" \"qa\" : {\n" +
|
||||
" \"properties\" : {\n" +
|
||||
|
@ -388,9 +407,11 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
" }\n" +
|
||||
" }\n" +
|
||||
" }" +
|
||||
"}", ContentType.APPLICATION_JSON);
|
||||
client().performRequest(HttpPut.METHOD_NAME, "/" + indexName, Collections.emptyMap(), parentMapping);
|
||||
StringEntity questionDoc = new StringEntity("{\n" +
|
||||
"}");
|
||||
client().performRequest(createIndex);
|
||||
Request questionDoc = new Request(HttpPut.METHOD_NAME, "/" + indexName + "/qa/1");
|
||||
questionDoc.setJsonEntity(
|
||||
"{\n" +
|
||||
" \"body\": \"<p>I have Windows 2003 server and i bought a new Windows 2008 server...\",\n" +
|
||||
" \"title\": \"Whats the best way to file transfer my site from server to a newer one?\",\n" +
|
||||
" \"tags\": [\n" +
|
||||
|
@ -399,9 +420,12 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
" \"file-transfer\"\n" +
|
||||
" ],\n" +
|
||||
" \"qa_join_field\" : \"question\"\n" +
|
||||
"}", ContentType.APPLICATION_JSON);
|
||||
client().performRequest(HttpPut.METHOD_NAME, "/" + indexName + "/qa/1", Collections.emptyMap(), questionDoc);
|
||||
StringEntity answerDoc1 = new StringEntity("{\n" +
|
||||
"}");
|
||||
client().performRequest(questionDoc);
|
||||
Request answerDoc1 = new Request(HttpPut.METHOD_NAME, "/" + indexName + "/qa/2");
|
||||
answerDoc1.addParameter("routing", "1");
|
||||
answerDoc1.setJsonEntity(
|
||||
"{\n" +
|
||||
" \"owner\": {\n" +
|
||||
" \"location\": \"Norfolk, United Kingdom\",\n" +
|
||||
" \"display_name\": \"Sam\",\n" +
|
||||
|
@ -413,9 +437,12 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
" \"parent\" : \"1\"\n" +
|
||||
" },\n" +
|
||||
" \"creation_date\": \"2009-05-04T13:45:37.030\"\n" +
|
||||
"}", ContentType.APPLICATION_JSON);
|
||||
client().performRequest(HttpPut.METHOD_NAME, "/" + indexName + "/qa/2", Collections.singletonMap("routing", "1"), answerDoc1);
|
||||
StringEntity answerDoc2 = new StringEntity("{\n" +
|
||||
"}");
|
||||
client().performRequest(answerDoc1);
|
||||
Request answerDoc2 = new Request(HttpPut.METHOD_NAME, "/" + indexName + "/qa/3");
|
||||
answerDoc2.addParameter("routing", "1");
|
||||
answerDoc2.setJsonEntity(
|
||||
"{\n" +
|
||||
" \"owner\": {\n" +
|
||||
" \"location\": \"Norfolk, United Kingdom\",\n" +
|
||||
" \"display_name\": \"Troll\",\n" +
|
||||
|
@ -427,9 +454,9 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
" \"parent\" : \"1\"\n" +
|
||||
" },\n" +
|
||||
" \"creation_date\": \"2009-05-05T13:45:37.030\"\n" +
|
||||
"}", ContentType.APPLICATION_JSON);
|
||||
client().performRequest(HttpPut.METHOD_NAME, "/" + indexName + "/qa/3", Collections.singletonMap("routing", "1"), answerDoc2);
|
||||
client().performRequest(HttpPost.METHOD_NAME, "/_refresh");
|
||||
"}");
|
||||
client().performRequest(answerDoc2);
|
||||
client().performRequest(new Request(HttpPost.METHOD_NAME, "/_refresh"));
|
||||
|
||||
TermsAggregationBuilder leafTermAgg = new TermsAggregationBuilder("top-names", ValueType.STRING)
|
||||
.field("owner.display_name.keyword").size(10);
|
||||
|
@ -506,9 +533,10 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
}
|
||||
|
||||
public void testSearchWithWeirdScriptFields() throws Exception {
|
||||
HttpEntity entity = new NStringEntity("{ \"field\":\"value\"}", ContentType.APPLICATION_JSON);
|
||||
client().performRequest("PUT", "test/type/1", Collections.emptyMap(), entity);
|
||||
client().performRequest("POST", "/test/_refresh");
|
||||
Request doc = new Request("PUT", "test/type/1");
|
||||
doc.setJsonEntity("{\"field\":\"value\"}");
|
||||
client().performRequest(doc);
|
||||
client().performRequest(new Request("POST", "/test/_refresh"));
|
||||
|
||||
{
|
||||
SearchRequest searchRequest = new SearchRequest("test").source(SearchSourceBuilder.searchSource()
|
||||
|
@ -547,13 +575,13 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
}
|
||||
|
||||
public void testSearchScroll() throws Exception {
|
||||
|
||||
for (int i = 0; i < 100; i++) {
|
||||
XContentBuilder builder = jsonBuilder().startObject().field("field", i).endObject();
|
||||
HttpEntity entity = new NStringEntity(Strings.toString(builder), ContentType.APPLICATION_JSON);
|
||||
client().performRequest(HttpPut.METHOD_NAME, "test/type1/" + Integer.toString(i), Collections.emptyMap(), entity);
|
||||
Request doc = new Request(HttpPut.METHOD_NAME, "/test/type1/" + Integer.toString(i));
|
||||
doc.setJsonEntity(Strings.toString(builder));
|
||||
client().performRequest(doc);
|
||||
}
|
||||
client().performRequest(HttpPost.METHOD_NAME, "/test/_refresh");
|
||||
client().performRequest(new Request(HttpPost.METHOD_NAME, "/test/_refresh"));
|
||||
|
||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(35).sort("field", SortOrder.ASC);
|
||||
SearchRequest searchRequest = new SearchRequest("test").scroll(TimeValue.timeValueMinutes(2)).source(searchSourceBuilder);
|
||||
|
@ -878,11 +906,11 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
|
||||
assertToXContentEquivalent(expectedSource, actualSource, XContentType.JSON);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void testMultiSearchTemplate() throws Exception {
|
||||
MultiSearchTemplateRequest multiSearchTemplateRequest = new MultiSearchTemplateRequest();
|
||||
|
||||
|
||||
SearchTemplateRequest goodRequest = new SearchTemplateRequest();
|
||||
goodRequest.setRequest(new SearchRequest("index"));
|
||||
goodRequest.setScriptType(ScriptType.INLINE);
|
||||
|
@ -900,8 +928,8 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
goodRequest.setExplain(true);
|
||||
goodRequest.setProfile(true);
|
||||
multiSearchTemplateRequest.add(goodRequest);
|
||||
|
||||
|
||||
|
||||
|
||||
SearchTemplateRequest badRequest = new SearchTemplateRequest();
|
||||
badRequest.setRequest(new SearchRequest("index"));
|
||||
badRequest.setScriptType(ScriptType.INLINE);
|
||||
|
@ -910,17 +938,17 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
scriptParams.put("number", 10);
|
||||
badRequest.setScriptParams(scriptParams);
|
||||
|
||||
multiSearchTemplateRequest.add(badRequest);
|
||||
|
||||
multiSearchTemplateRequest.add(badRequest);
|
||||
|
||||
MultiSearchTemplateResponse multiSearchTemplateResponse =
|
||||
execute(multiSearchTemplateRequest, highLevelClient()::multiSearchTemplate,
|
||||
execute(multiSearchTemplateRequest, highLevelClient()::multiSearchTemplate,
|
||||
highLevelClient()::multiSearchTemplateAsync);
|
||||
|
||||
|
||||
Item[] responses = multiSearchTemplateResponse.getResponses();
|
||||
|
||||
|
||||
assertEquals(2, responses.length);
|
||||
|
||||
|
||||
|
||||
|
||||
assertNull(responses[0].getResponse().getSource());
|
||||
SearchResponse goodResponse =responses[0].getResponse().getResponse();
|
||||
assertNotNull(goodResponse);
|
||||
|
@ -930,18 +958,18 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
assertThat(goodResponse.getHits().getMaxScore(), greaterThan(0f));
|
||||
SearchHit hit = goodResponse.getHits().getHits()[0];
|
||||
assertNotNull(hit.getExplanation());
|
||||
assertFalse(goodResponse.getProfileResults().isEmpty());
|
||||
|
||||
|
||||
assertFalse(goodResponse.getProfileResults().isEmpty());
|
||||
|
||||
|
||||
assertNull(responses[0].getResponse().getSource());
|
||||
assertThat(responses[1].isFailure(), Matchers.is(true));
|
||||
assertNotNull(responses[1].getFailureMessage());
|
||||
assertNotNull(responses[1].getFailureMessage());
|
||||
assertThat(responses[1].getFailureMessage(), containsString("json_parse_exception"));
|
||||
}
|
||||
|
||||
|
||||
public void testMultiSearchTemplateAllBad() throws Exception {
|
||||
MultiSearchTemplateRequest multiSearchTemplateRequest = new MultiSearchTemplateRequest();
|
||||
|
||||
|
||||
SearchTemplateRequest badRequest1 = new SearchTemplateRequest();
|
||||
badRequest1.setRequest(new SearchRequest("index"));
|
||||
badRequest1.setScriptType(ScriptType.INLINE);
|
||||
|
@ -957,8 +985,8 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
scriptParams.put("number", "BAD NUMBER");
|
||||
badRequest1.setScriptParams(scriptParams);
|
||||
multiSearchTemplateRequest.add(badRequest1);
|
||||
|
||||
|
||||
|
||||
|
||||
SearchTemplateRequest badRequest2 = new SearchTemplateRequest();
|
||||
badRequest2.setRequest(new SearchRequest("index"));
|
||||
badRequest2.setScriptType(ScriptType.INLINE);
|
||||
|
@ -967,13 +995,13 @@ public class SearchIT extends ESRestHighLevelClientTestCase {
|
|||
scriptParams.put("number", "BAD NUMBER");
|
||||
badRequest2.setScriptParams(scriptParams);
|
||||
|
||||
multiSearchTemplateRequest.add(badRequest2);
|
||||
|
||||
// The whole HTTP request should fail if no nested search requests are valid
|
||||
multiSearchTemplateRequest.add(badRequest2);
|
||||
|
||||
// The whole HTTP request should fail if no nested search requests are valid
|
||||
ElasticsearchStatusException exception = expectThrows(ElasticsearchStatusException.class,
|
||||
() -> execute(multiSearchTemplateRequest, highLevelClient()::multiSearchTemplate,
|
||||
() -> execute(multiSearchTemplateRequest, highLevelClient()::multiSearchTemplate,
|
||||
highLevelClient()::multiSearchTemplateAsync));
|
||||
|
||||
|
||||
assertEquals(RestStatus.BAD_REQUEST, exception.status());
|
||||
assertThat(exception.getMessage(), containsString("no requests added"));
|
||||
}
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
package org.elasticsearch.client.documentation;
|
||||
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.nio.entity.NStringEntity;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.DocWriteRequest;
|
||||
|
@ -66,7 +64,6 @@ import org.elasticsearch.script.Script;
|
|||
import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -756,7 +753,9 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
public void testGet() throws Exception {
|
||||
RestHighLevelClient client = highLevelClient();
|
||||
{
|
||||
String mappings = "{\n" +
|
||||
Request createIndex = new Request("PUT", "/posts");
|
||||
createIndex.setJsonEntity(
|
||||
"{\n" +
|
||||
" \"mappings\" : {\n" +
|
||||
" \"doc\" : {\n" +
|
||||
" \"properties\" : {\n" +
|
||||
|
@ -767,10 +766,8 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
NStringEntity entity = new NStringEntity(mappings, ContentType.APPLICATION_JSON);
|
||||
Response response = client().performRequest("PUT", "/posts", Collections.emptyMap(), entity);
|
||||
"}");
|
||||
Response response = client().performRequest(createIndex);
|
||||
assertEquals(200, response.getStatusLine().getStatusCode());
|
||||
|
||||
IndexRequest indexRequest = new IndexRequest("posts", "doc", "1")
|
||||
|
@ -1071,21 +1068,21 @@ public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase {
|
|||
RestHighLevelClient client = highLevelClient();
|
||||
|
||||
{
|
||||
String mappings = "{\n" +
|
||||
" \"mappings\" : {\n" +
|
||||
" \"type\" : {\n" +
|
||||
" \"properties\" : {\n" +
|
||||
" \"foo\" : {\n" +
|
||||
" \"type\": \"text\",\n" +
|
||||
" \"store\": true\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}";
|
||||
|
||||
NStringEntity entity = new NStringEntity(mappings, ContentType.APPLICATION_JSON);
|
||||
Response response = client().performRequest("PUT", "/index", Collections.emptyMap(), entity);
|
||||
Request createIndex = new Request("PUT", "/index");
|
||||
createIndex.setJsonEntity(
|
||||
"{\n" +
|
||||
" \"mappings\" : {\n" +
|
||||
" \"type\" : {\n" +
|
||||
" \"properties\" : {\n" +
|
||||
" \"foo\" : {\n" +
|
||||
" \"type\": \"text\",\n" +
|
||||
" \"store\": true\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}");
|
||||
Response response = client().performRequest(createIndex);
|
||||
assertEquals(200, response.getStatusLine().getStatusCode());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue