Skip to content

Deprecate types in explain requests. #35611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,10 @@ static Request count(CountRequest countRequest) throws IOException {
}

static Request explain(ExplainRequest explainRequest) throws IOException {
Request request = new Request(HttpGet.METHOD_NAME,
endpoint(explainRequest.index(), explainRequest.type(), explainRequest.id(), "_explain"));
String endpoint = explainRequest.isTypeless()
? endpoint(explainRequest.index(), "_explain", explainRequest.id())
: endpoint(explainRequest.index(), explainRequest.type(), explainRequest.id(), "_explain");
Request request = new Request(HttpGet.METHOD_NAME, endpoint);

Params params = new Params(request);
params.withStoredFields(explainRequest.storedFields());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1225,10 +1225,9 @@ public void testMultiSearchTemplate() throws Exception {

public void testExplain() throws IOException {
String index = randomAlphaOfLengthBetween(3, 10);
String type = randomAlphaOfLengthBetween(3, 10);
String id = randomAlphaOfLengthBetween(3, 10);

ExplainRequest explainRequest = new ExplainRequest(index, type, id);
ExplainRequest explainRequest = new ExplainRequest(index, id);
explainRequest.query(QueryBuilders.termQuery(randomAlphaOfLengthBetween(3, 10), randomAlphaOfLengthBetween(3, 10)));

Map<String, String> expectedParams = new HashMap<>();
Expand All @@ -1254,18 +1253,28 @@ public void testExplain() throws IOException {
}

Request request = RequestConverters.explain(explainRequest);
StringJoiner endpoint = new StringJoiner("/", "/", "");
endpoint.add(index)
.add(type)
.add(id)
.add("_explain");

assertEquals(HttpGet.METHOD_NAME, request.getMethod());
assertEquals(endpoint.toString(), request.getEndpoint());
assertEquals("/" + index + "/_explain/" + id, request.getEndpoint());

assertEquals(expectedParams, request.getParameters());
assertToXContentBody(explainRequest, request.getEntity());
}

public void testExplainWithType() throws IOException {
String index = randomAlphaOfLengthBetween(3, 10);
String type = randomAlphaOfLengthBetween(3, 10);
String id = randomAlphaOfLengthBetween(3, 10);

ExplainRequest explainRequest = new ExplainRequest(index, type, id);
explainRequest.query(QueryBuilders.termQuery(randomAlphaOfLengthBetween(3, 10), randomAlphaOfLengthBetween(3, 10)));

Request request = RequestConverters.explain(explainRequest);
assertEquals(HttpGet.METHOD_NAME, request.getMethod());
assertEquals("/" + index + "/" + type + "/" + id + "/_explain", request.getEndpoint());

assertToXContentBody(explainRequest, request.getEntity());
}

public void testTermVectors() throws IOException {
String index = randomAlphaOfLengthBetween(3, 10);
String id = randomAlphaOfLengthBetween(3, 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ public void indexDocuments() throws IOException {
}

{
Request doc1 = new Request(HttpPut.METHOD_NAME, "/index1/doc/1");
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");
Request doc2 = new Request(HttpPut.METHOD_NAME, "/index1/_doc/2");
doc2.setJsonEntity("{\"field\":\"value2\"}");
client().performRequest(doc2);
}
Expand All @@ -131,7 +131,7 @@ public void indexDocuments() throws IOException {
create.setJsonEntity(
"{" +
" \"mappings\": {" +
" \"doc\": {" +
" \"_doc\": {" +
" \"properties\": {" +
" \"rating\": {" +
" \"type\": \"keyword\"" +
Expand All @@ -141,19 +141,19 @@ public void indexDocuments() throws IOException {
" }" +
"}");
client().performRequest(create);
Request doc3 = new Request(HttpPut.METHOD_NAME, "/index2/doc/3");
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");
Request doc4 = new Request(HttpPut.METHOD_NAME, "/index2/_doc/4");
doc4.setJsonEntity("{\"field\":\"value2\"}");
client().performRequest(doc4);
}

{
Request doc5 = new Request(HttpPut.METHOD_NAME, "/index3/doc/5");
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");
Request doc6 = new Request(HttpPut.METHOD_NAME, "/index3/_doc/6");
doc6.setJsonEntity("{\"field\":\"value2\"}");
client().performRequest(doc6);
}
Expand All @@ -163,7 +163,7 @@ public void indexDocuments() throws IOException {
create.setJsonEntity(
"{" +
" \"mappings\": {" +
" \"doc\": {" +
" \"_doc\": {" +
" \"properties\": {" +
" \"field1\": {" +
" \"type\": \"keyword\"," +
Expand All @@ -178,7 +178,7 @@ public void indexDocuments() throws IOException {
" }" +
"}");
client().performRequest(create);
Request doc1 = new Request(HttpPut.METHOD_NAME, "/index4/doc/1");
Request doc1 = new Request(HttpPut.METHOD_NAME, "/index4/_doc/1");
doc1.setJsonEntity("{\"field1\":\"value1\", \"field2\":\"value2\"}");
client().performRequest(doc1);

Expand Down Expand Up @@ -1010,13 +1010,13 @@ public void testMultiSearchTemplateAllBad() throws Exception {

public void testExplain() throws IOException {
{
ExplainRequest explainRequest = new ExplainRequest("index1", "doc", "1");
ExplainRequest explainRequest = new ExplainRequest("index1", "1");
explainRequest.query(QueryBuilders.matchAllQuery());

ExplainResponse explainResponse = execute(explainRequest, highLevelClient()::explain, highLevelClient()::explainAsync);

assertThat(explainResponse.getIndex(), equalTo("index1"));
assertThat(explainResponse.getType(), equalTo("doc"));
assertThat(explainResponse.getType(), equalTo("_doc"));
assertThat(Integer.valueOf(explainResponse.getId()), equalTo(1));
assertTrue(explainResponse.isExists());
assertTrue(explainResponse.isMatch());
Expand All @@ -1025,13 +1025,13 @@ public void testExplain() throws IOException {
assertNull(explainResponse.getGetResult());
}
{
ExplainRequest explainRequest = new ExplainRequest("index1", "doc", "1");
ExplainRequest explainRequest = new ExplainRequest("index1", "1");
explainRequest.query(QueryBuilders.termQuery("field", "value1"));

ExplainResponse explainResponse = execute(explainRequest, highLevelClient()::explain, highLevelClient()::explainAsync);

assertThat(explainResponse.getIndex(), equalTo("index1"));
assertThat(explainResponse.getType(), equalTo("doc"));
assertThat(explainResponse.getType(), equalTo("_doc"));
assertThat(Integer.valueOf(explainResponse.getId()), equalTo(1));
assertTrue(explainResponse.isExists());
assertTrue(explainResponse.isMatch());
Expand All @@ -1040,29 +1040,29 @@ public void testExplain() throws IOException {
assertNull(explainResponse.getGetResult());
}
{
ExplainRequest explainRequest = new ExplainRequest("index1", "doc", "1");
ExplainRequest explainRequest = new ExplainRequest("index1", "1");
explainRequest.query(QueryBuilders.termQuery("field", "value2"));

ExplainResponse explainResponse = execute(explainRequest, highLevelClient()::explain, highLevelClient()::explainAsync);

assertThat(explainResponse.getIndex(), equalTo("index1"));
assertThat(explainResponse.getType(), equalTo("doc"));
assertThat(explainResponse.getType(), equalTo("_doc"));
assertThat(Integer.valueOf(explainResponse.getId()), equalTo(1));
assertTrue(explainResponse.isExists());
assertFalse(explainResponse.isMatch());
assertTrue(explainResponse.hasExplanation());
assertNull(explainResponse.getGetResult());
}
{
ExplainRequest explainRequest = new ExplainRequest("index1", "doc", "1");
ExplainRequest explainRequest = new ExplainRequest("index1", "1");
explainRequest.query(QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery("field", "value1"))
.must(QueryBuilders.termQuery("field", "value2")));

ExplainResponse explainResponse = execute(explainRequest, highLevelClient()::explain, highLevelClient()::explainAsync);

assertThat(explainResponse.getIndex(), equalTo("index1"));
assertThat(explainResponse.getType(), equalTo("doc"));
assertThat(explainResponse.getType(), equalTo("_doc"));
assertThat(Integer.valueOf(explainResponse.getId()), equalTo(1));
assertTrue(explainResponse.isExists());
assertFalse(explainResponse.isMatch());
Expand All @@ -1074,7 +1074,7 @@ public void testExplain() throws IOException {

public void testExplainNonExistent() throws IOException {
{
ExplainRequest explainRequest = new ExplainRequest("non_existent_index", "doc", "1");
ExplainRequest explainRequest = new ExplainRequest("non_existent_index", "1");
explainRequest.query(QueryBuilders.matchQuery("field", "value"));
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
() -> execute(explainRequest, highLevelClient()::explain, highLevelClient()::explainAsync));
Expand All @@ -1084,13 +1084,13 @@ public void testExplainNonExistent() throws IOException {
containsString("Elasticsearch exception [type=index_not_found_exception, reason=no such index [non_existent_index]]"));
}
{
ExplainRequest explainRequest = new ExplainRequest("index1", "doc", "999");
ExplainRequest explainRequest = new ExplainRequest("index1", "999");
explainRequest.query(QueryBuilders.matchQuery("field", "value1"));

ExplainResponse explainResponse = execute(explainRequest, highLevelClient()::explain, highLevelClient()::explainAsync);

assertThat(explainResponse.getIndex(), equalTo("index1"));
assertThat(explainResponse.getType(), equalTo("doc"));
assertThat(explainResponse.getType(), equalTo("_doc"));
assertThat(explainResponse.getId(), equalTo("999"));
assertFalse(explainResponse.isExists());
assertFalse(explainResponse.isMatch());
Expand All @@ -1101,7 +1101,7 @@ public void testExplainNonExistent() throws IOException {

public void testExplainWithStoredFields() throws IOException {
{
ExplainRequest explainRequest = new ExplainRequest("index4", "doc", "1");
ExplainRequest explainRequest = new ExplainRequest("index4", "1");
explainRequest.query(QueryBuilders.matchAllQuery());
explainRequest.storedFields(new String[]{"field1"});

Expand All @@ -1117,7 +1117,7 @@ public void testExplainWithStoredFields() throws IOException {
assertTrue(explainResponse.getGetResult().isSourceEmpty());
}
{
ExplainRequest explainRequest = new ExplainRequest("index4", "doc", "1");
ExplainRequest explainRequest = new ExplainRequest("index4", "1");
explainRequest.query(QueryBuilders.matchAllQuery());
explainRequest.storedFields(new String[]{"field1", "field2"});

Expand All @@ -1137,7 +1137,7 @@ public void testExplainWithStoredFields() throws IOException {

public void testExplainWithFetchSource() throws IOException {
{
ExplainRequest explainRequest = new ExplainRequest("index4", "doc", "1");
ExplainRequest explainRequest = new ExplainRequest("index4", "1");
explainRequest.query(QueryBuilders.matchAllQuery());
explainRequest.fetchSourceContext(new FetchSourceContext(true, new String[]{"field1"}, null));

Expand All @@ -1151,7 +1151,7 @@ public void testExplainWithFetchSource() throws IOException {
assertThat(explainResponse.getGetResult().getSource(), equalTo(Collections.singletonMap("field1", "value1")));
}
{
ExplainRequest explainRequest = new ExplainRequest("index4", "doc", "1");
ExplainRequest explainRequest = new ExplainRequest("index4", "1");
explainRequest.query(QueryBuilders.matchAllQuery());
explainRequest.fetchSourceContext(new FetchSourceContext(true, null, new String[] {"field2"}));

Expand All @@ -1167,7 +1167,7 @@ public void testExplainWithFetchSource() throws IOException {
}

public void testExplainWithAliasFilter() throws IOException {
ExplainRequest explainRequest = new ExplainRequest("alias4", "doc", "1");
ExplainRequest explainRequest = new ExplainRequest("alias4", "1");
explainRequest.query(QueryBuilders.matchAllQuery());

ExplainResponse explainResponse = execute(explainRequest, highLevelClient()::explain, highLevelClient()::explainAsync);
Expand Down
Loading