Skip to content

Commit

Permalink
Remove types from explain API (#46926)
Browse files Browse the repository at this point in the history
We no longer need a type to get the source of a document, so we can remove it from
the explain API as well.

Relates to #41059
  • Loading branch information
romseygeek authored Sep 23, 2019
1 parent 88a4a86 commit b733f9e
Show file tree
Hide file tree
Showing 27 changed files with 65 additions and 458 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,7 @@ static Request count(CountRequest countRequest) throws IOException {
}

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

Params params = new Params();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1415,21 +1415,6 @@ public void testExplain() throws IOException {
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 @@ -1093,7 +1093,6 @@ public void testExplain() throws IOException {
ExplainResponse explainResponse = execute(explainRequest, highLevelClient()::explain, highLevelClient()::explainAsync);

assertThat(explainResponse.getIndex(), equalTo("index1"));
assertThat(explainResponse.getType(), equalTo("_doc"));
assertThat(Integer.valueOf(explainResponse.getId()), equalTo(1));
assertTrue(explainResponse.isExists());
assertTrue(explainResponse.isMatch());
Expand All @@ -1108,7 +1107,6 @@ public void testExplain() throws IOException {
ExplainResponse explainResponse = execute(explainRequest, highLevelClient()::explain, highLevelClient()::explainAsync);

assertThat(explainResponse.getIndex(), equalTo("index1"));
assertThat(explainResponse.getType(), equalTo("_doc"));
assertThat(Integer.valueOf(explainResponse.getId()), equalTo(1));
assertTrue(explainResponse.isExists());
assertTrue(explainResponse.isMatch());
Expand All @@ -1123,7 +1121,6 @@ public void testExplain() throws IOException {
ExplainResponse explainResponse = execute(explainRequest, highLevelClient()::explain, highLevelClient()::explainAsync);

assertThat(explainResponse.getIndex(), equalTo("index1"));
assertThat(explainResponse.getType(), equalTo("_doc"));
assertThat(Integer.valueOf(explainResponse.getId()), equalTo(1));
assertTrue(explainResponse.isExists());
assertFalse(explainResponse.isMatch());
Expand All @@ -1139,7 +1136,6 @@ public void testExplain() throws IOException {
ExplainResponse explainResponse = execute(explainRequest, highLevelClient()::explain, highLevelClient()::explainAsync);

assertThat(explainResponse.getIndex(), equalTo("index1"));
assertThat(explainResponse.getType(), equalTo("_doc"));
assertThat(Integer.valueOf(explainResponse.getId()), equalTo(1));
assertTrue(explainResponse.isExists());
assertFalse(explainResponse.isMatch());
Expand Down Expand Up @@ -1167,7 +1163,6 @@ public void testExplainNonExistent() throws IOException {
ExplainResponse explainResponse = execute(explainRequest, highLevelClient()::explain, highLevelClient()::explainAsync);

assertThat(explainResponse.getIndex(), equalTo("index1"));
assertThat(explainResponse.getType(), equalTo("_doc"));
assertThat(explainResponse.getId(), equalTo("999"));
assertFalse(explainResponse.isExists());
assertFalse(explainResponse.isMatch());
Expand Down
1 change: 0 additions & 1 deletion docs/reference/search/explain.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ The API returns the following response:
--------------------------------------------------
{
"_index":"twitter",
"_type":"_doc",
"_id":"0",
"matched":true,
"explanation":{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ public void testExplainUsage() throws Exception {
assertHitCount(searchResponse, 1L);
assertThat(searchResponse.getHits().getAt(0).getExplanation().getDescription(), containsString("join value p1"));

ExplainResponse explainResponse = client().prepareExplain("test", "doc", parentId)
ExplainResponse explainResponse = client().prepareExplain("test", parentId)
.setQuery(hasChildQuery("child", termQuery("c_field", "1"), ScoreMode.Max))
.get();
assertThat(explainResponse.isExists(), equalTo(true));
Expand Down
26 changes: 0 additions & 26 deletions rest-api-spec/src/main/resources/rest-api-spec/api/explain.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,6 @@
"description":"The name of the index"
}
}
},
{
"path":"/{index}/{type}/{id}/_explain",
"methods":[
"GET",
"POST"
],
"parts":{
"id":{
"type":"string",
"description":"The document ID"
},
"index":{
"type":"string",
"description":"The name of the index"
},
"type":{
"type":"string",
"description":"The type of the document",
"deprecated":true
}
},
"deprecated":{
"version":"7.0.0",
"description":"Specifying types in urls has been deprecated"
}
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ setup:
- is_true: matched
- match: { explanation.value: 1 }
- match: { _index: test_1 }
- match: { _type: _doc }
- match: { _id: id_1 }

---
Expand All @@ -49,7 +48,6 @@ setup:
- is_true: matched
- match: { explanation.value: 1 }
- match: { _index: test_1 }
- match: { _type: _doc }
- match: { _id: id_1 }

---
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
- do:
explain: { index: test_1, id: 1, _source: false, body: { query: { match_all: {}} } }
- match: { _index: test_1 }
- match: { _type: _doc }
- match: { _id: "1" }
- is_false: get._source

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit b733f9e

Please sign in to comment.