Skip to content

Commit 8783105

Browse files
authored
Deprecate types in explain requests. (#35611)
The following updates were made: - Add a new untyped endpoint `{index}/_explain/{id}`. - Add deprecation warnings to Rest*Action, plus tests in Rest*ActionTests. - For each REST yml test, make sure there is one version without types, and another legacy version that retains types (called *_with_types.yml). - Deprecate relevant methods on the Java HLRC requests/ responses. - Update documentation (for both the REST API and Java HLRC).
1 parent a0da390 commit 8783105

File tree

21 files changed

+450
-112
lines changed

21 files changed

+450
-112
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,10 @@ static Request count(CountRequest countRequest) throws IOException {
462462
}
463463

464464
static Request explain(ExplainRequest explainRequest) throws IOException {
465-
Request request = new Request(HttpGet.METHOD_NAME,
466-
endpoint(explainRequest.index(), explainRequest.type(), explainRequest.id(), "_explain"));
465+
String endpoint = explainRequest.isTypeless()
466+
? endpoint(explainRequest.index(), "_explain", explainRequest.id())
467+
: endpoint(explainRequest.index(), explainRequest.type(), explainRequest.id(), "_explain");
468+
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
467469

468470
Params params = new Params(request);
469471
params.withStoredFields(explainRequest.storedFields());

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

+18-9
Original file line numberDiff line numberDiff line change
@@ -1225,10 +1225,9 @@ public void testMultiSearchTemplate() throws Exception {
12251225

12261226
public void testExplain() throws IOException {
12271227
String index = randomAlphaOfLengthBetween(3, 10);
1228-
String type = randomAlphaOfLengthBetween(3, 10);
12291228
String id = randomAlphaOfLengthBetween(3, 10);
12301229

1231-
ExplainRequest explainRequest = new ExplainRequest(index, type, id);
1230+
ExplainRequest explainRequest = new ExplainRequest(index, id);
12321231
explainRequest.query(QueryBuilders.termQuery(randomAlphaOfLengthBetween(3, 10), randomAlphaOfLengthBetween(3, 10)));
12331232

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

12561255
Request request = RequestConverters.explain(explainRequest);
1257-
StringJoiner endpoint = new StringJoiner("/", "/", "");
1258-
endpoint.add(index)
1259-
.add(type)
1260-
.add(id)
1261-
.add("_explain");
1262-
12631256
assertEquals(HttpGet.METHOD_NAME, request.getMethod());
1264-
assertEquals(endpoint.toString(), request.getEndpoint());
1257+
assertEquals("/" + index + "/_explain/" + id, request.getEndpoint());
1258+
12651259
assertEquals(expectedParams, request.getParameters());
12661260
assertToXContentBody(explainRequest, request.getEntity());
12671261
}
12681262

1263+
public void testExplainWithType() throws IOException {
1264+
String index = randomAlphaOfLengthBetween(3, 10);
1265+
String type = randomAlphaOfLengthBetween(3, 10);
1266+
String id = randomAlphaOfLengthBetween(3, 10);
1267+
1268+
ExplainRequest explainRequest = new ExplainRequest(index, type, id);
1269+
explainRequest.query(QueryBuilders.termQuery(randomAlphaOfLengthBetween(3, 10), randomAlphaOfLengthBetween(3, 10)));
1270+
1271+
Request request = RequestConverters.explain(explainRequest);
1272+
assertEquals(HttpGet.METHOD_NAME, request.getMethod());
1273+
assertEquals("/" + index + "/" + type + "/" + id + "/_explain", request.getEndpoint());
1274+
1275+
assertToXContentBody(explainRequest, request.getEntity());
1276+
}
1277+
12691278
public void testTermVectors() throws IOException {
12701279
String index = randomAlphaOfLengthBetween(3, 10);
12711280
String id = randomAlphaOfLengthBetween(3, 10);

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

+25-25
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ public void indexDocuments() throws IOException {
118118
}
119119

120120
{
121-
Request doc1 = new Request(HttpPut.METHOD_NAME, "/index1/doc/1");
121+
Request doc1 = new Request(HttpPut.METHOD_NAME, "/index1/_doc/1");
122122
doc1.setJsonEntity("{\"field\":\"value1\", \"rating\": 7}");
123123
client().performRequest(doc1);
124-
Request doc2 = new Request(HttpPut.METHOD_NAME, "/index1/doc/2");
124+
Request doc2 = new Request(HttpPut.METHOD_NAME, "/index1/_doc/2");
125125
doc2.setJsonEntity("{\"field\":\"value2\"}");
126126
client().performRequest(doc2);
127127
}
@@ -131,7 +131,7 @@ public void indexDocuments() throws IOException {
131131
create.setJsonEntity(
132132
"{" +
133133
" \"mappings\": {" +
134-
" \"doc\": {" +
134+
" \"_doc\": {" +
135135
" \"properties\": {" +
136136
" \"rating\": {" +
137137
" \"type\": \"keyword\"" +
@@ -141,19 +141,19 @@ public void indexDocuments() throws IOException {
141141
" }" +
142142
"}");
143143
client().performRequest(create);
144-
Request doc3 = new Request(HttpPut.METHOD_NAME, "/index2/doc/3");
144+
Request doc3 = new Request(HttpPut.METHOD_NAME, "/index2/_doc/3");
145145
doc3.setJsonEntity("{\"field\":\"value1\", \"rating\": \"good\"}");
146146
client().performRequest(doc3);
147-
Request doc4 = new Request(HttpPut.METHOD_NAME, "/index2/doc/4");
147+
Request doc4 = new Request(HttpPut.METHOD_NAME, "/index2/_doc/4");
148148
doc4.setJsonEntity("{\"field\":\"value2\"}");
149149
client().performRequest(doc4);
150150
}
151151

152152
{
153-
Request doc5 = new Request(HttpPut.METHOD_NAME, "/index3/doc/5");
153+
Request doc5 = new Request(HttpPut.METHOD_NAME, "/index3/_doc/5");
154154
doc5.setJsonEntity("{\"field\":\"value1\"}");
155155
client().performRequest(doc5);
156-
Request doc6 = new Request(HttpPut.METHOD_NAME, "/index3/doc/6");
156+
Request doc6 = new Request(HttpPut.METHOD_NAME, "/index3/_doc/6");
157157
doc6.setJsonEntity("{\"field\":\"value2\"}");
158158
client().performRequest(doc6);
159159
}
@@ -163,7 +163,7 @@ public void indexDocuments() throws IOException {
163163
create.setJsonEntity(
164164
"{" +
165165
" \"mappings\": {" +
166-
" \"doc\": {" +
166+
" \"_doc\": {" +
167167
" \"properties\": {" +
168168
" \"field1\": {" +
169169
" \"type\": \"keyword\"," +
@@ -178,7 +178,7 @@ public void indexDocuments() throws IOException {
178178
" }" +
179179
"}");
180180
client().performRequest(create);
181-
Request doc1 = new Request(HttpPut.METHOD_NAME, "/index4/doc/1");
181+
Request doc1 = new Request(HttpPut.METHOD_NAME, "/index4/_doc/1");
182182
doc1.setJsonEntity("{\"field1\":\"value1\", \"field2\":\"value2\"}");
183183
client().performRequest(doc1);
184184

@@ -1010,13 +1010,13 @@ public void testMultiSearchTemplateAllBad() throws Exception {
10101010

10111011
public void testExplain() throws IOException {
10121012
{
1013-
ExplainRequest explainRequest = new ExplainRequest("index1", "doc", "1");
1013+
ExplainRequest explainRequest = new ExplainRequest("index1", "1");
10141014
explainRequest.query(QueryBuilders.matchAllQuery());
10151015

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

10181018
assertThat(explainResponse.getIndex(), equalTo("index1"));
1019-
assertThat(explainResponse.getType(), equalTo("doc"));
1019+
assertThat(explainResponse.getType(), equalTo("_doc"));
10201020
assertThat(Integer.valueOf(explainResponse.getId()), equalTo(1));
10211021
assertTrue(explainResponse.isExists());
10221022
assertTrue(explainResponse.isMatch());
@@ -1025,13 +1025,13 @@ public void testExplain() throws IOException {
10251025
assertNull(explainResponse.getGetResult());
10261026
}
10271027
{
1028-
ExplainRequest explainRequest = new ExplainRequest("index1", "doc", "1");
1028+
ExplainRequest explainRequest = new ExplainRequest("index1", "1");
10291029
explainRequest.query(QueryBuilders.termQuery("field", "value1"));
10301030

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

10331033
assertThat(explainResponse.getIndex(), equalTo("index1"));
1034-
assertThat(explainResponse.getType(), equalTo("doc"));
1034+
assertThat(explainResponse.getType(), equalTo("_doc"));
10351035
assertThat(Integer.valueOf(explainResponse.getId()), equalTo(1));
10361036
assertTrue(explainResponse.isExists());
10371037
assertTrue(explainResponse.isMatch());
@@ -1040,29 +1040,29 @@ public void testExplain() throws IOException {
10401040
assertNull(explainResponse.getGetResult());
10411041
}
10421042
{
1043-
ExplainRequest explainRequest = new ExplainRequest("index1", "doc", "1");
1043+
ExplainRequest explainRequest = new ExplainRequest("index1", "1");
10441044
explainRequest.query(QueryBuilders.termQuery("field", "value2"));
10451045

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

10481048
assertThat(explainResponse.getIndex(), equalTo("index1"));
1049-
assertThat(explainResponse.getType(), equalTo("doc"));
1049+
assertThat(explainResponse.getType(), equalTo("_doc"));
10501050
assertThat(Integer.valueOf(explainResponse.getId()), equalTo(1));
10511051
assertTrue(explainResponse.isExists());
10521052
assertFalse(explainResponse.isMatch());
10531053
assertTrue(explainResponse.hasExplanation());
10541054
assertNull(explainResponse.getGetResult());
10551055
}
10561056
{
1057-
ExplainRequest explainRequest = new ExplainRequest("index1", "doc", "1");
1057+
ExplainRequest explainRequest = new ExplainRequest("index1", "1");
10581058
explainRequest.query(QueryBuilders.boolQuery()
10591059
.must(QueryBuilders.termQuery("field", "value1"))
10601060
.must(QueryBuilders.termQuery("field", "value2")));
10611061

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

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

10751075
public void testExplainNonExistent() throws IOException {
10761076
{
1077-
ExplainRequest explainRequest = new ExplainRequest("non_existent_index", "doc", "1");
1077+
ExplainRequest explainRequest = new ExplainRequest("non_existent_index", "1");
10781078
explainRequest.query(QueryBuilders.matchQuery("field", "value"));
10791079
ElasticsearchException exception = expectThrows(ElasticsearchException.class,
10801080
() -> execute(explainRequest, highLevelClient()::explain, highLevelClient()::explainAsync));
@@ -1084,13 +1084,13 @@ public void testExplainNonExistent() throws IOException {
10841084
containsString("Elasticsearch exception [type=index_not_found_exception, reason=no such index [non_existent_index]]"));
10851085
}
10861086
{
1087-
ExplainRequest explainRequest = new ExplainRequest("index1", "doc", "999");
1087+
ExplainRequest explainRequest = new ExplainRequest("index1", "999");
10881088
explainRequest.query(QueryBuilders.matchQuery("field", "value1"));
10891089

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

10921092
assertThat(explainResponse.getIndex(), equalTo("index1"));
1093-
assertThat(explainResponse.getType(), equalTo("doc"));
1093+
assertThat(explainResponse.getType(), equalTo("_doc"));
10941094
assertThat(explainResponse.getId(), equalTo("999"));
10951095
assertFalse(explainResponse.isExists());
10961096
assertFalse(explainResponse.isMatch());
@@ -1101,7 +1101,7 @@ public void testExplainNonExistent() throws IOException {
11011101

11021102
public void testExplainWithStoredFields() throws IOException {
11031103
{
1104-
ExplainRequest explainRequest = new ExplainRequest("index4", "doc", "1");
1104+
ExplainRequest explainRequest = new ExplainRequest("index4", "1");
11051105
explainRequest.query(QueryBuilders.matchAllQuery());
11061106
explainRequest.storedFields(new String[]{"field1"});
11071107

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

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

11381138
public void testExplainWithFetchSource() throws IOException {
11391139
{
1140-
ExplainRequest explainRequest = new ExplainRequest("index4", "doc", "1");
1140+
ExplainRequest explainRequest = new ExplainRequest("index4", "1");
11411141
explainRequest.query(QueryBuilders.matchAllQuery());
11421142
explainRequest.fetchSourceContext(new FetchSourceContext(true, new String[]{"field1"}, null));
11431143

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

@@ -1167,7 +1167,7 @@ public void testExplainWithFetchSource() throws IOException {
11671167
}
11681168

11691169
public void testExplainWithAliasFilter() throws IOException {
1170-
ExplainRequest explainRequest = new ExplainRequest("alias4", "doc", "1");
1170+
ExplainRequest explainRequest = new ExplainRequest("alias4", "1");
11711171
explainRequest.query(QueryBuilders.matchAllQuery());
11721172

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

0 commit comments

Comments
 (0)