2929import  org .elasticsearch .action .admin .indices .alias .IndicesAliasesRequest ;
3030import  org .elasticsearch .action .index .IndexRequest ;
3131import  org .elasticsearch .action .search .SearchRequest ;
32+ import  org .elasticsearch .action .update .UpdateRequest ;
3233import  org .elasticsearch .client .indices .PutIndexTemplateRequest ;
3334import  org .elasticsearch .common .lucene .search .function .CombineFunction ;
3435import  org .elasticsearch .common .lucene .search .function .FunctionScoreQuery ;
5758import  org .springframework .data .elasticsearch .core .index .AliasActionParameters ;
5859import  org .springframework .data .elasticsearch .core .index .AliasActions ;
5960import  org .springframework .data .elasticsearch .core .index .PutTemplateRequest ;
60- import  org .springframework .data .elasticsearch .core .reindex .ReindexRequest ;
61- import  org .springframework .data .elasticsearch .core .reindex .Remote ;
6261import  org .springframework .data .elasticsearch .core .mapping .IndexCoordinates ;
6362import  org .springframework .data .elasticsearch .core .mapping .SimpleElasticsearchMappingContext ;
6463import  org .springframework .data .elasticsearch .core .query .*;
6564import  org .springframework .data .elasticsearch .core .query .RescorerQuery .ScoreMode ;
65+ import  org .springframework .data .elasticsearch .core .reindex .ReindexRequest ;
66+ import  org .springframework .data .elasticsearch .core .reindex .Remote ;
6667import  org .springframework .lang .Nullable ;
6768
6869/** 
@@ -92,7 +93,8 @@ static void setUpAll() {
9293		requestFactory  = new  RequestFactory ((converter ));
9394	}
9495
95- 	@ Test  // FPI-734 
96+ 	@ Test 
97+ 	// FPI-734 
9698	void  shouldBuildSearchWithGeoSortSort () throws  JSONException  {
9799		CriteriaQuery  query  = new  CriteriaQuery (new  Criteria ("lastName" ).is ("Smith" ));
98100		Sort  sort  = Sort .by (new  GeoDistanceOrder ("location" , new  GeoPoint (49.0 , 8.4 )));
@@ -140,7 +142,8 @@ void shouldBuildSearchWithGeoSortSort() throws JSONException {
140142		assertEquals (expected , searchRequest , false );
141143	}
142144
143- 	@ Test  // DATAES-449 
145+ 	@ Test 
146+ 	// DATAES-449 
144147	void  shouldAddRouting () {
145148		String  route  = "route66" ;
146149		CriteriaQuery  query  = new  CriteriaQuery (new  Criteria ("lastName" ).is ("Smith" ));
@@ -152,7 +155,8 @@ void shouldAddRouting() {
152155		assertThat (searchRequest .routing ()).isEqualTo (route );
153156	}
154157
155- 	@ Test  // DATAES-765 
158+ 	@ Test 
159+ 	// DATAES-765 
156160	void  shouldAddMaxQueryWindowForUnpagedToRequest () {
157161		Query  query  = new  NativeSearchQueryBuilder ().withQuery (matchAllQuery ()).withPageable (Pageable .unpaged ()).build ();
158162
@@ -162,7 +166,8 @@ void shouldAddMaxQueryWindowForUnpagedToRequest() {
162166		assertThat (searchRequest .source ().size ()).isEqualTo (RequestFactory .INDEX_MAX_RESULT_WINDOW );
163167	}
164168
165- 	@ Test  // DATAES-799 
169+ 	@ Test 
170+ 	// DATAES-799 
166171	void  shouldIncludeSeqNoAndPrimaryTermFromIndexQueryToIndexRequest () {
167172		IndexQuery  query  = new  IndexQuery ();
168173		query .setObject (new  Person ());
@@ -175,7 +180,8 @@ void shouldIncludeSeqNoAndPrimaryTermFromIndexQueryToIndexRequest() {
175180		assertThat (request .ifPrimaryTerm ()).isEqualTo (2L );
176181	}
177182
178- 	@ Test  // DATAES-799 
183+ 	@ Test 
184+ 	// DATAES-799 
179185	void  shouldNotRequestSeqNoAndPrimaryTermWhenEntityClassDoesNotContainSeqNoPrimaryTermProperty () {
180186		Query  query  = new  NativeSearchQueryBuilder ().build ();
181187
@@ -184,7 +190,8 @@ void shouldNotRequestSeqNoAndPrimaryTermWhenEntityClassDoesNotContainSeqNoPrimar
184190		assertThat (request .source ().seqNoAndPrimaryTerm ()).isNull ();
185191	}
186192
187- 	@ Test  // DATAES-799 
193+ 	@ Test 
194+ 	// DATAES-799 
188195	void  shouldRequestSeqNoAndPrimaryTermWhenEntityClassContainsSeqNoPrimaryTermProperty () {
189196		Query  query  = new  NativeSearchQueryBuilder ().build ();
190197
@@ -194,7 +201,8 @@ void shouldRequestSeqNoAndPrimaryTermWhenEntityClassContainsSeqNoPrimaryTermProp
194201		assertThat (request .source ().seqNoAndPrimaryTerm ()).isTrue ();
195202	}
196203
197- 	@ Test  // DATAES-799 
204+ 	@ Test 
205+ 	// DATAES-799 
198206	void  shouldNotRequestSeqNoAndPrimaryTermWhenEntityClassIsNull () {
199207		Query  query  = new  NativeSearchQueryBuilder ().build ();
200208
@@ -203,7 +211,8 @@ void shouldNotRequestSeqNoAndPrimaryTermWhenEntityClassIsNull() {
203211		assertThat (request .source ().seqNoAndPrimaryTerm ()).isNull ();
204212	}
205213
206- 	@ Test  // DATAES-864 
214+ 	@ Test 
215+ 	// DATAES-864 
207216	void  shouldBuildIndicesAliasRequest () throws  IOException , JSONException  {
208217
209218		AliasActions  aliasActions  = new  AliasActions ();
@@ -316,7 +325,8 @@ void shouldBuildIndicesAliasRequest() throws IOException, JSONException {
316325		assertEquals (expected , json , false );
317326	}
318327
319- 	@ Test  // DATAES-612 
328+ 	@ Test 
329+ 	// DATAES-612 
320330	void  shouldCreatePutIndexTemplateRequest () throws  JSONException , IOException  {
321331
322332		String  expected  = "{\n "  + // 
@@ -430,7 +440,8 @@ private String requestToString(ToXContent request) throws IOException {
430440		return  XContentHelper .toXContent (request , XContentType .JSON , true ).utf8ToString ();
431441	}
432442
433- 	@ Test  // #1686 
443+ 	@ Test 
444+ 	// #1686 
434445	void  shouldBuildSearchWithRescorerQuery () throws  JSONException  {
435446		CriteriaQuery  query  = new  CriteriaQuery (new  Criteria ("lastName" ).is ("Smith" ));
436447		RescorerQuery  rescorerQuery  = new  RescorerQuery (new  NativeSearchQueryBuilder () // 
@@ -546,7 +557,7 @@ void shouldSetRequestCacheFalseOnSearchRequest() {
546557		assertThat (searchRequest .requestCache ()).isFalse ();
547558	}
548559
549- 	@ Test 
560+ 	@ Test   // #2004 
550561	@ DisplayName ("should set stored fields on SearchRequest" )
551562	void  shouldSetStoredFieldsOnSearchRequest () {
552563
@@ -560,7 +571,8 @@ void shouldSetStoredFieldsOnSearchRequest() {
560571				.isEqualTo (Arrays .asList ("last-name" , "current-location" ));
561572	}
562573
563- 	@ Test  // #1529 
574+ 	@ Test 
575+ 	// #1529 
564576	void  shouldCreateReindexRequest () throws  IOException , JSONException  {
565577		final  String  expected  = "{\n "  + // 
566578				"    \" source\" :{\n "  + // 
@@ -608,6 +620,7 @@ void shouldCreateReindexRequest() throws IOException, JSONException {
608620	}
609621
610622	@ Test 
623+ 	// #1529 
611624	void  shouldAllowSourceQueryForReindexWithoutRemote () throws  IOException , JSONException  {
612625		final  String  expected  = "{\n "  + // 
613626				"    \" source\" :{\n "  + // 
@@ -644,6 +657,59 @@ void shouldNotFailOnEmptyWildcardStatesOnToElasticsearchIndicesOptions() {
644657				.isNotNull ();
645658	}
646659
660+ 	@ Test  // #2043 
661+ 	@ DisplayName ("should use index name from query if set in bulk index" )
662+ 	void  shouldUseIndexNameFromQueryIfSetInBulkIndex () {
663+ 
664+ 		String  queryIndexName  = "query-index-name" ;
665+ 		String  methodIndexName  = "method-index-name" ;
666+ 		IndexQuery  indexQuery  = new  IndexQueryBuilder ().withIndex (queryIndexName ).withId ("42" ).withObject (new  Person ())
667+ 				.build ();
668+ 
669+ 		IndexRequest  indexRequest  = requestFactory .indexRequest (indexQuery , IndexCoordinates .of (methodIndexName ));
670+ 
671+ 		assertThat (indexRequest .index ()).isEqualTo (queryIndexName );
672+ 	}
673+ 
674+ 	@ Test  // #2043 
675+ 	@ DisplayName ("should use index name from method if none is set in query in bulk index" )
676+ 	void  shouldUseIndexNameFromMethodIfNoneIsSetInQueryInBulkIndex () {
677+ 
678+ 		String  methodIndexName  = "method-index-name" ;
679+ 		IndexQuery  indexQuery  = new  IndexQueryBuilder ().withId ("42" ).withObject (new  Person ()).build ();
680+ 
681+ 		IndexRequest  indexRequest  = requestFactory .indexRequest (indexQuery , IndexCoordinates .of (methodIndexName ));
682+ 
683+ 		assertThat (indexRequest .index ()).isEqualTo (methodIndexName );
684+ 	}
685+ 
686+ 	@ Test  // #2043 
687+ 	@ DisplayName ("should use index name from query if set in bulk update" )
688+ 	void  shouldUseIndexNameFromQueryIfSetInBulkUpdate () {
689+ 
690+ 		String  queryIndexName  = "query-index-name" ;
691+ 		String  methodIndexName  = "method-index-name" ;
692+ 		UpdateQuery  updateQuery  = UpdateQuery .builder ("42" ).withIndex (queryIndexName )
693+ 				.withDocument (org .springframework .data .elasticsearch .core .document .Document .create ()).build ();
694+ 
695+ 		UpdateRequest  updateRequest  = requestFactory .updateRequest (updateQuery , IndexCoordinates .of (methodIndexName ));
696+ 
697+ 		assertThat (updateRequest .index ()).isEqualTo (queryIndexName );
698+ 	}
699+ 
700+ 	@ Test  // #2043 
701+ 	@ DisplayName ("should use index name from method if none is set in query in bulk update" )
702+ 	void  shouldUseIndexNameFromMethodIfNoneIsSetInQueryInBulkUpdate () {
703+ 
704+ 		String  methodIndexName  = "method-index-name" ;
705+ 		UpdateQuery  updateQuery  = UpdateQuery .builder ("42" )
706+ 				.withDocument (org .springframework .data .elasticsearch .core .document .Document .create ()).build ();
707+ 
708+ 		UpdateRequest  updateRequest  = requestFactory .updateRequest (updateQuery , IndexCoordinates .of (methodIndexName ));
709+ 
710+ 		assertThat (updateRequest .index ()).isEqualTo (methodIndexName );
711+ 	}
712+ 
647713	// region entities 
648714	static  class  Person  {
649715		@ Nullable 
0 commit comments