29
29
import org .elasticsearch .action .admin .indices .alias .IndicesAliasesRequest ;
30
30
import org .elasticsearch .action .index .IndexRequest ;
31
31
import org .elasticsearch .action .search .SearchRequest ;
32
+ import org .elasticsearch .action .update .UpdateRequest ;
32
33
import org .elasticsearch .client .indices .PutIndexTemplateRequest ;
33
34
import org .elasticsearch .common .lucene .search .function .CombineFunction ;
34
35
import org .elasticsearch .common .lucene .search .function .FunctionScoreQuery ;
57
58
import org .springframework .data .elasticsearch .core .index .AliasActionParameters ;
58
59
import org .springframework .data .elasticsearch .core .index .AliasActions ;
59
60
import 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 ;
62
61
import org .springframework .data .elasticsearch .core .mapping .IndexCoordinates ;
63
62
import org .springframework .data .elasticsearch .core .mapping .SimpleElasticsearchMappingContext ;
64
63
import org .springframework .data .elasticsearch .core .query .*;
65
64
import 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 ;
66
67
import org .springframework .lang .Nullable ;
67
68
68
69
/**
@@ -92,7 +93,8 @@ static void setUpAll() {
92
93
requestFactory = new RequestFactory ((converter ));
93
94
}
94
95
95
- @ Test // FPI-734
96
+ @ Test
97
+ // FPI-734
96
98
void shouldBuildSearchWithGeoSortSort () throws JSONException {
97
99
CriteriaQuery query = new CriteriaQuery (new Criteria ("lastName" ).is ("Smith" ));
98
100
Sort sort = Sort .by (new GeoDistanceOrder ("location" , new GeoPoint (49.0 , 8.4 )));
@@ -140,7 +142,8 @@ void shouldBuildSearchWithGeoSortSort() throws JSONException {
140
142
assertEquals (expected , searchRequest , false );
141
143
}
142
144
143
- @ Test // DATAES-449
145
+ @ Test
146
+ // DATAES-449
144
147
void shouldAddRouting () {
145
148
String route = "route66" ;
146
149
CriteriaQuery query = new CriteriaQuery (new Criteria ("lastName" ).is ("Smith" ));
@@ -152,7 +155,8 @@ void shouldAddRouting() {
152
155
assertThat (searchRequest .routing ()).isEqualTo (route );
153
156
}
154
157
155
- @ Test // DATAES-765
158
+ @ Test
159
+ // DATAES-765
156
160
void shouldAddMaxQueryWindowForUnpagedToRequest () {
157
161
Query query = new NativeSearchQueryBuilder ().withQuery (matchAllQuery ()).withPageable (Pageable .unpaged ()).build ();
158
162
@@ -162,7 +166,8 @@ void shouldAddMaxQueryWindowForUnpagedToRequest() {
162
166
assertThat (searchRequest .source ().size ()).isEqualTo (RequestFactory .INDEX_MAX_RESULT_WINDOW );
163
167
}
164
168
165
- @ Test // DATAES-799
169
+ @ Test
170
+ // DATAES-799
166
171
void shouldIncludeSeqNoAndPrimaryTermFromIndexQueryToIndexRequest () {
167
172
IndexQuery query = new IndexQuery ();
168
173
query .setObject (new Person ());
@@ -175,7 +180,8 @@ void shouldIncludeSeqNoAndPrimaryTermFromIndexQueryToIndexRequest() {
175
180
assertThat (request .ifPrimaryTerm ()).isEqualTo (2L );
176
181
}
177
182
178
- @ Test // DATAES-799
183
+ @ Test
184
+ // DATAES-799
179
185
void shouldNotRequestSeqNoAndPrimaryTermWhenEntityClassDoesNotContainSeqNoPrimaryTermProperty () {
180
186
Query query = new NativeSearchQueryBuilder ().build ();
181
187
@@ -184,7 +190,8 @@ void shouldNotRequestSeqNoAndPrimaryTermWhenEntityClassDoesNotContainSeqNoPrimar
184
190
assertThat (request .source ().seqNoAndPrimaryTerm ()).isNull ();
185
191
}
186
192
187
- @ Test // DATAES-799
193
+ @ Test
194
+ // DATAES-799
188
195
void shouldRequestSeqNoAndPrimaryTermWhenEntityClassContainsSeqNoPrimaryTermProperty () {
189
196
Query query = new NativeSearchQueryBuilder ().build ();
190
197
@@ -194,7 +201,8 @@ void shouldRequestSeqNoAndPrimaryTermWhenEntityClassContainsSeqNoPrimaryTermProp
194
201
assertThat (request .source ().seqNoAndPrimaryTerm ()).isTrue ();
195
202
}
196
203
197
- @ Test // DATAES-799
204
+ @ Test
205
+ // DATAES-799
198
206
void shouldNotRequestSeqNoAndPrimaryTermWhenEntityClassIsNull () {
199
207
Query query = new NativeSearchQueryBuilder ().build ();
200
208
@@ -203,7 +211,8 @@ void shouldNotRequestSeqNoAndPrimaryTermWhenEntityClassIsNull() {
203
211
assertThat (request .source ().seqNoAndPrimaryTerm ()).isNull ();
204
212
}
205
213
206
- @ Test // DATAES-864
214
+ @ Test
215
+ // DATAES-864
207
216
void shouldBuildIndicesAliasRequest () throws IOException , JSONException {
208
217
209
218
AliasActions aliasActions = new AliasActions ();
@@ -316,7 +325,8 @@ void shouldBuildIndicesAliasRequest() throws IOException, JSONException {
316
325
assertEquals (expected , json , false );
317
326
}
318
327
319
- @ Test // DATAES-612
328
+ @ Test
329
+ // DATAES-612
320
330
void shouldCreatePutIndexTemplateRequest () throws JSONException , IOException {
321
331
322
332
String expected = "{\n " + //
@@ -430,7 +440,8 @@ private String requestToString(ToXContent request) throws IOException {
430
440
return XContentHelper .toXContent (request , XContentType .JSON , true ).utf8ToString ();
431
441
}
432
442
433
- @ Test // #1686
443
+ @ Test
444
+ // #1686
434
445
void shouldBuildSearchWithRescorerQuery () throws JSONException {
435
446
CriteriaQuery query = new CriteriaQuery (new Criteria ("lastName" ).is ("Smith" ));
436
447
RescorerQuery rescorerQuery = new RescorerQuery (new NativeSearchQueryBuilder () //
@@ -546,7 +557,7 @@ void shouldSetRequestCacheFalseOnSearchRequest() {
546
557
assertThat (searchRequest .requestCache ()).isFalse ();
547
558
}
548
559
549
- @ Test
560
+ @ Test // #2004
550
561
@ DisplayName ("should set stored fields on SearchRequest" )
551
562
void shouldSetStoredFieldsOnSearchRequest () {
552
563
@@ -560,7 +571,8 @@ void shouldSetStoredFieldsOnSearchRequest() {
560
571
.isEqualTo (Arrays .asList ("last-name" , "current-location" ));
561
572
}
562
573
563
- @ Test // #1529
574
+ @ Test
575
+ // #1529
564
576
void shouldCreateReindexRequest () throws IOException , JSONException {
565
577
final String expected = "{\n " + //
566
578
" \" source\" :{\n " + //
@@ -608,6 +620,7 @@ void shouldCreateReindexRequest() throws IOException, JSONException {
608
620
}
609
621
610
622
@ Test
623
+ // #1529
611
624
void shouldAllowSourceQueryForReindexWithoutRemote () throws IOException , JSONException {
612
625
final String expected = "{\n " + //
613
626
" \" source\" :{\n " + //
@@ -644,6 +657,59 @@ void shouldNotFailOnEmptyWildcardStatesOnToElasticsearchIndicesOptions() {
644
657
.isNotNull ();
645
658
}
646
659
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
+
647
713
// region entities
648
714
static class Person {
649
715
@ Nullable
0 commit comments