@@ -1337,11 +1337,21 @@ public void testMTVApi() throws Exception {
1337
1337
assertThat (response .getResponses ()[0 ].getResponse ().getFields ().terms ("field2" ).size (), equalTo (1L ));
1338
1338
}
1339
1339
1340
- public void testParentChild_parentField () {
1340
+ public void testParentChild_parentField () throws Exception {
1341
+ XContentBuilder mapping = XContentFactory .jsonBuilder ().startObject ()
1342
+ .startObject ("_parent" )
1343
+ .field ("type" , "parent" )
1344
+ .endObject ()
1345
+ .startObject ("properties" )
1346
+ .startObject ("field1" )
1347
+ .field ("type" , "keyword" )
1348
+ .endObject ()
1349
+ .endObject ()
1350
+ .endObject ();
1341
1351
assertAcked (prepareCreate ("test" )
1342
1352
.setSettings (Settings .builder ().put ("index.version.created" , Version .V_5_6_0 .id ))
1343
1353
.addMapping ("parent" )
1344
- .addMapping ("child" , "_parent" , "type=parent" ));
1354
+ .addMapping ("child" , mapping ));
1345
1355
ensureGreen ();
1346
1356
1347
1357
// index simple data
@@ -1388,7 +1398,25 @@ public void testParentChild_joinField() throws Exception {
1388
1398
source .put ("join_field" , joinField );
1389
1399
client ().prepareIndex ("test" , "doc" , "c2" ).setSource (source ).setRouting ("p1" ).get ();
1390
1400
refresh ();
1401
+
1391
1402
verifyParentChild ();
1403
+
1404
+ // Perform the same checks, but using an alias for field1.
1405
+ SearchResponse searchResponse = client ()
1406
+ .filterWithHeader (Collections .singletonMap (BASIC_AUTH_HEADER , basicAuthHeaderValue ("user1" , USERS_PASSWD )))
1407
+ .prepareSearch ("test" )
1408
+ .setQuery (hasChildQuery ("child" , termQuery ("alias" , "yellow" ), ScoreMode .None ))
1409
+ .get ();
1410
+ assertHitCount (searchResponse , 1L );
1411
+ assertThat (searchResponse .getHits ().getTotalHits (), equalTo (1L ));
1412
+ assertThat (searchResponse .getHits ().getAt (0 ).getId (), equalTo ("p1" ));
1413
+
1414
+ searchResponse = client ()
1415
+ .filterWithHeader (Collections .singletonMap (BASIC_AUTH_HEADER , basicAuthHeaderValue ("user2" , USERS_PASSWD )))
1416
+ .prepareSearch ("test" )
1417
+ .setQuery (hasChildQuery ("child" , termQuery ("alias" , "yellow" ), ScoreMode .None ))
1418
+ .get ();
1419
+ assertHitCount (searchResponse , 0L );
1392
1420
}
1393
1421
1394
1422
private void verifyParentChild () {
@@ -1407,23 +1435,6 @@ private void verifyParentChild() {
1407
1435
.setQuery (hasChildQuery ("child" , termQuery ("field1" , "yellow" ), ScoreMode .None ))
1408
1436
.get ();
1409
1437
assertHitCount (searchResponse , 0L );
1410
-
1411
- // Perform the same checks, but using an alias for field1.
1412
- searchResponse = client ()
1413
- .filterWithHeader (Collections .singletonMap (BASIC_AUTH_HEADER , basicAuthHeaderValue ("user1" , USERS_PASSWD )))
1414
- .prepareSearch ("test" )
1415
- .setQuery (hasChildQuery ("child" , termQuery ("alias" , "yellow" ), ScoreMode .None ))
1416
- .get ();
1417
- assertHitCount (searchResponse , 1L );
1418
- assertThat (searchResponse .getHits ().getTotalHits (), equalTo (1L ));
1419
- assertThat (searchResponse .getHits ().getAt (0 ).getId (), equalTo ("p1" ));
1420
-
1421
- searchResponse = client ()
1422
- .filterWithHeader (Collections .singletonMap (BASIC_AUTH_HEADER , basicAuthHeaderValue ("user2" , USERS_PASSWD )))
1423
- .prepareSearch ("test" )
1424
- .setQuery (hasChildQuery ("child" , termQuery ("alias" , "yellow" ), ScoreMode .None ))
1425
- .get ();
1426
- assertHitCount (searchResponse , 0L );
1427
1438
}
1428
1439
1429
1440
public void testUpdateApiIsBlocked () throws Exception {
0 commit comments