22
22
import org .apache .http .util .EntityUtils ;
23
23
import org .elasticsearch .Version ;
24
24
import org .elasticsearch .client .Request ;
25
- import org .elasticsearch .client .RequestOptions ;
26
25
import org .elasticsearch .client .Response ;
27
26
import org .elasticsearch .client .ResponseException ;
28
27
import org .elasticsearch .client .RestClient ;
29
- import org .elasticsearch .test .rest .TypesRemovalWarningsHandler ;
28
+ import org .elasticsearch .rest .action .document .RestGetAction ;
29
+ import org .elasticsearch .rest .action .search .RestExplainAction ;
30
30
import org .elasticsearch .cluster .metadata .IndexMetaData ;
31
31
import org .elasticsearch .common .Booleans ;
32
32
import org .elasticsearch .common .CheckedFunction ;
@@ -82,7 +82,6 @@ public void setIndex() throws IOException {
82
82
index = getTestName ().toLowerCase (Locale .ROOT );
83
83
}
84
84
85
-
86
85
public void testSearch () throws Exception {
87
86
int count ;
88
87
if (isRunningAgainstOldCluster ()) {
@@ -96,7 +95,7 @@ public void testSearch() throws Exception {
96
95
}
97
96
{
98
97
mappingsAndSettings .startObject ("mappings" );
99
- mappingsAndSettings .startObject ("_doc " );
98
+ mappingsAndSettings .startObject ("doc " );
100
99
mappingsAndSettings .startObject ("properties" );
101
100
{
102
101
mappingsAndSettings .startObject ("string" );
@@ -162,7 +161,7 @@ public void testNewReplicasWork() throws Exception {
162
161
}
163
162
{
164
163
mappingsAndSettings .startObject ("mappings" );
165
- mappingsAndSettings .startObject ("_doc " );
164
+ mappingsAndSettings .startObject ("doc " );
166
165
mappingsAndSettings .startObject ("properties" );
167
166
{
168
167
mappingsAndSettings .startObject ("field" );
@@ -233,7 +232,7 @@ public void testAliasWithBadName() throws Exception {
233
232
}
234
233
{
235
234
mappingsAndSettings .startObject ("mappings" );
236
- mappingsAndSettings .startObject ("_doc " );
235
+ mappingsAndSettings .startObject ("doc " );
237
236
mappingsAndSettings .startObject ("properties" );
238
237
{
239
238
mappingsAndSettings .startObject ("key" );
@@ -336,7 +335,7 @@ public void testShrink() throws IOException {
336
335
mappingsAndSettings .startObject ();
337
336
{
338
337
mappingsAndSettings .startObject ("mappings" );
339
- mappingsAndSettings .startObject ("_doc " );
338
+ mappingsAndSettings .startObject ("doc " );
340
339
mappingsAndSettings .startObject ("properties" );
341
340
{
342
341
mappingsAndSettings .startObject ("field" );
@@ -404,7 +403,7 @@ public void testShrinkAfterUpgrade() throws IOException {
404
403
mappingsAndSettings .startObject ();
405
404
{
406
405
mappingsAndSettings .startObject ("mappings" );
407
- mappingsAndSettings .startObject ("_doc " );
406
+ mappingsAndSettings .startObject ("doc " );
408
407
mappingsAndSettings .startObject ("properties" );
409
408
{
410
409
mappingsAndSettings .startObject ("field" );
@@ -492,7 +491,7 @@ public void testRollover() throws IOException {
492
491
bulk .append ("{\" index\" :{}}\n " );
493
492
bulk .append ("{\" test\" :\" test\" }\n " );
494
493
}
495
- Request bulkRequest = new Request ("POST" , "/" + index + "_write/_doc /_bulk" );
494
+ Request bulkRequest = new Request ("POST" , "/" + index + "_write/doc /_bulk" );
496
495
bulkRequest .setJsonEntity (bulk .toString ());
497
496
bulkRequest .addParameter ("refresh" , "" );
498
497
assertThat (EntityUtils .toString (client ().performRequest (bulkRequest ).getEntity ()), containsString ("\" errors\" :false" ));
@@ -571,19 +570,15 @@ void assertAllSearchWorks(int count) throws IOException {
571
570
String type = (String ) bestHit .get ("_type" );
572
571
String id = (String ) bestHit .get ("_id" );
573
572
574
- Request explanationRequest = new Request ("GET" , "/" + index + "/" + type + "/" + id + "/_explain" );
575
- explanationRequest .setJsonEntity ("{ \" query\" : { \" match_all\" : {} }}" );
576
-
577
- RequestOptions .Builder explanationOptions = RequestOptions .DEFAULT .toBuilder ();
578
- explanationOptions .setWarningsHandler (TypesRemovalWarningsHandler .INSTANCE );
579
- explanationRequest .setOptions (explanationOptions );
580
-
581
- String explanation = toStr (client ().performRequest (explanationRequest ));
573
+ Request explainRequest = new Request ("GET" , "/" + index + "/" + type + "/" + id + "/_explain" );
574
+ explainRequest .setJsonEntity ("{ \" query\" : { \" match_all\" : {} }}" );
575
+ explainRequest .setOptions (expectWarnings (RestExplainAction .TYPES_DEPRECATION_MESSAGE ));
576
+ String explanation = toStr (client ().performRequest (explainRequest ));
582
577
assertFalse ("Could not find payload boost in explanation\n " + explanation , explanation .contains ("payloadBoost" ));
583
578
584
579
// Make sure the query can run on the whole index
585
580
Request searchRequest = new Request ("GET" , "/" + index + "/_search" );
586
- searchRequest .setEntity (explanationRequest .getEntity ());
581
+ searchRequest .setEntity (explainRequest .getEntity ());
587
582
searchRequest .addParameter ("explain" , "true" );
588
583
Map <?, ?> matchAllResponse = entityAsMap (client ().performRequest (searchRequest ));
589
584
assertNoFailures (matchAllResponse );
@@ -628,11 +623,13 @@ void assertRealtimeGetWorks() throws IOException {
628
623
Map <?, ?> hit = (Map <?, ?>) ((List <?>)(XContentMapValues .extractValue ("hits.hits" , searchResponse ))).get (0 );
629
624
String docId = (String ) hit .get ("_id" );
630
625
631
- Request updateRequest = new Request ("POST" , "/" + index + "/_doc /" + docId + "/_update" );
626
+ Request updateRequest = new Request ("POST" , "/" + index + "/doc /" + docId + "/_update" );
632
627
updateRequest .setJsonEntity ("{ \" doc\" : { \" foo\" : \" bar\" }}" );
633
628
client ().performRequest (updateRequest );
634
629
635
- Map <String , Object > getRsp = entityAsMap (client ().performRequest (new Request ("GET" , "/" + index + "/_doc/" + docId )));
630
+ Request getRequest = new Request ("GET" , "/" + index + "/doc/" + docId );
631
+ getRequest .setOptions (expectWarnings (RestGetAction .TYPES_DEPRECATION_MESSAGE ));
632
+ Map <String , Object > getRsp = entityAsMap (client ().performRequest (getRequest ));
636
633
Map <?, ?> source = (Map <?, ?>) getRsp .get ("_source" );
637
634
assertTrue ("doc does not contain 'foo' key: " + source , source .containsKey ("foo" ));
638
635
@@ -685,7 +682,7 @@ int extractTotalHits(Map<?, ?> response) {
685
682
* Tests that a single document survives. Super basic smoke test.
686
683
*/
687
684
public void testSingleDoc () throws IOException {
688
- String docLocation = "/" + index + "/_doc /1" ;
685
+ String docLocation = "/" + index + "/doc /1" ;
689
686
String doc = "{\" test\" : \" test\" }" ;
690
687
691
688
if (isRunningAgainstOldCluster ()) {
@@ -694,7 +691,10 @@ public void testSingleDoc() throws IOException {
694
691
client ().performRequest (createDoc );
695
692
}
696
693
697
- assertThat (toStr (client ().performRequest (new Request ("GET" , docLocation ))), containsString (doc ));
694
+
695
+ Request request = new Request ("GET" , docLocation );
696
+ request .setOptions (expectWarnings (RestGetAction .TYPES_DEPRECATION_MESSAGE ));
697
+ assertThat (toStr (client ().performRequest (request )), containsString (doc ));
698
698
}
699
699
700
700
/**
@@ -872,7 +872,7 @@ public void testSnapshotRestore() throws IOException {
872
872
}
873
873
templateBuilder .endObject ();
874
874
templateBuilder .startObject ("mappings" ); {
875
- templateBuilder .startObject ("_doc " ); {
875
+ templateBuilder .startObject ("doc " ); {
876
876
templateBuilder .startObject ("_source" ); {
877
877
templateBuilder .field ("enabled" , true );
878
878
}
@@ -982,7 +982,7 @@ public void testSoftDeletes() throws Exception {
982
982
int numDocs = between (10 , 100 );
983
983
for (int i = 0 ; i < numDocs ; i ++) {
984
984
String doc = Strings .toString (JsonXContent .contentBuilder ().startObject ().field ("field" , "v1" ).endObject ());
985
- Request request = new Request ("POST" , "/" + index + "/_doc /" + i );
985
+ Request request = new Request ("POST" , "/" + index + "/doc /" + i );
986
986
request .setJsonEntity (doc );
987
987
client ().performRequest (request );
988
988
if (rarely ()) {
@@ -995,11 +995,11 @@ public void testSoftDeletes() throws Exception {
995
995
for (int i = 0 ; i < numDocs ; i ++) {
996
996
if (randomBoolean ()) {
997
997
String doc = Strings .toString (JsonXContent .contentBuilder ().startObject ().field ("field" , "v2" ).endObject ());
998
- Request request = new Request ("POST" , "/" + index + "/_doc /" + i );
998
+ Request request = new Request ("POST" , "/" + index + "/doc /" + i );
999
999
request .setJsonEntity (doc );
1000
1000
client ().performRequest (request );
1001
1001
} else if (randomBoolean ()) {
1002
- client ().performRequest (new Request ("DELETE" , "/" + index + "/_doc /" + i ));
1002
+ client ().performRequest (new Request ("DELETE" , "/" + index + "/doc /" + i ));
1003
1003
liveDocs --;
1004
1004
}
1005
1005
}
@@ -1065,7 +1065,7 @@ private void checkSnapshot(String snapshotName, int count, Version tookOnVersion
1065
1065
bulk .append ("{\" index\" :{\" _id\" :\" " ).append (count + i ).append ("\" }}\n " );
1066
1066
bulk .append ("{\" test\" :\" test\" }\n " );
1067
1067
}
1068
- Request writeToRestoredRequest = new Request ("POST" , "/restored_" + index + "/_doc /_bulk" );
1068
+ Request writeToRestoredRequest = new Request ("POST" , "/restored_" + index + "/doc /_bulk" );
1069
1069
writeToRestoredRequest .addParameter ("refresh" , "true" );
1070
1070
writeToRestoredRequest .setJsonEntity (bulk .toString ());
1071
1071
assertThat (EntityUtils .toString (client ().performRequest (writeToRestoredRequest ).getEntity ()), containsString ("\" errors\" :false" ));
@@ -1097,7 +1097,7 @@ private void checkSnapshot(String snapshotName, int count, Version tookOnVersion
1097
1097
expectedTemplate .put ("index_patterns" , singletonList ("evil_*" ));
1098
1098
}
1099
1099
expectedTemplate .put ("settings" , singletonMap ("index" , singletonMap ("number_of_shards" , "1" )));
1100
- expectedTemplate .put ("mappings" , singletonMap ("_doc " , singletonMap ("_source" , singletonMap ("enabled" , true ))));
1100
+ expectedTemplate .put ("mappings" , singletonMap ("doc " , singletonMap ("_source" , singletonMap ("enabled" , true ))));
1101
1101
expectedTemplate .put ("order" , 0 );
1102
1102
Map <String , Object > aliases = new HashMap <>();
1103
1103
aliases .put ("alias1" , emptyMap ());
@@ -1118,7 +1118,7 @@ private void indexRandomDocuments(int count, boolean flushAllowed, boolean saveI
1118
1118
logger .info ("Indexing {} random documents" , count );
1119
1119
for (int i = 0 ; i < count ; i ++) {
1120
1120
logger .debug ("Indexing document [{}]" , i );
1121
- Request createDocument = new Request ("POST" , "/" + index + "/_doc /" + i );
1121
+ Request createDocument = new Request ("POST" , "/" + index + "/doc /" + i );
1122
1122
createDocument .setJsonEntity (Strings .toString (docSupplier .apply (i )));
1123
1123
client ().performRequest (createDocument );
1124
1124
if (rarely ()) {
@@ -1143,15 +1143,16 @@ private void saveInfoDocument(String type, String value) throws IOException {
1143
1143
infoDoc .field ("value" , value );
1144
1144
infoDoc .endObject ();
1145
1145
// Only create the first version so we know how many documents are created when the index is first created
1146
- Request request = new Request ("PUT" , "/info/_doc /" + index + "_" + type );
1146
+ Request request = new Request ("PUT" , "/info/doc /" + index + "_" + type );
1147
1147
request .addParameter ("op_type" , "create" );
1148
1148
request .setJsonEntity (Strings .toString (infoDoc ));
1149
1149
client ().performRequest (request );
1150
1150
}
1151
1151
1152
1152
private String loadInfoDocument (String type ) throws IOException {
1153
- Request request = new Request ("GET" , "/info/_doc /" + index + "_" + type );
1153
+ Request request = new Request ("GET" , "/info/doc /" + index + "_" + type );
1154
1154
request .addParameter ("filter_path" , "_source" );
1155
+ request .setOptions (expectWarnings (RestGetAction .TYPES_DEPRECATION_MESSAGE ));
1155
1156
String doc = toStr (client ().performRequest (request ));
1156
1157
Matcher m = Pattern .compile ("\" value\" :\" (.+)\" " ).matcher (doc );
1157
1158
assertTrue (doc , m .find ());
0 commit comments