Skip to content

Commit a25c8f2

Browse files
authored
Βackporting fixes for randomization failures in rrf tests to 8x (elastic#114864)
1 parent ce5dc57 commit a25c8f2

File tree

4 files changed

+77
-15
lines changed

4 files changed

+77
-15
lines changed

x-pack/plugin/rank-rrf/src/internalClusterTest/java/org/elasticsearch/xpack/rank/rrf/RRFRetrieverBuilderIT.java

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,10 @@ public void testRRFPagination() {
174174
);
175175
// this one retrieves docs 2 and 6 due to prefilter
176176
StandardRetrieverBuilder standard1 = new StandardRetrieverBuilder(
177-
QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_2", "doc_3", "doc_6")).boost(20L)
177+
QueryBuilders.boolQuery()
178+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_2")).boost(20L))
179+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_3")).boost(10L))
180+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_6")).boost(5L))
178181
);
179182
standard1.getPreFilterQueryBuilders().add(QueryBuilders.queryStringQuery("search").defaultField(TEXT_FIELD));
180183
// this one retrieves docs 2, 3, 6, and 7
@@ -221,7 +224,10 @@ public void testRRFWithAggs() {
221224
);
222225
// this one retrieves docs 2 and 6 due to prefilter
223226
StandardRetrieverBuilder standard1 = new StandardRetrieverBuilder(
224-
QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_2", "doc_3", "doc_6")).boost(20L)
227+
QueryBuilders.boolQuery()
228+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_2")).boost(20L))
229+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_3")).boost(10L))
230+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_6")).boost(5L))
225231
);
226232
standard1.getPreFilterQueryBuilders().add(QueryBuilders.queryStringQuery("search").defaultField(TEXT_FIELD));
227233
// this one retrieves docs 2, 3, 6, and 7
@@ -273,7 +279,10 @@ public void testRRFWithCollapse() {
273279
);
274280
// this one retrieves docs 2 and 6 due to prefilter
275281
StandardRetrieverBuilder standard1 = new StandardRetrieverBuilder(
276-
QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_2", "doc_3", "doc_6")).boost(20L)
282+
QueryBuilders.boolQuery()
283+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_2")).boost(20L))
284+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_3")).boost(10L))
285+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_6")).boost(5L))
277286
);
278287
standard1.getPreFilterQueryBuilders().add(QueryBuilders.queryStringQuery("search").defaultField(TEXT_FIELD));
279288
// this one retrieves docs 2, 3, 6, and 7
@@ -327,7 +336,10 @@ public void testRRFRetrieverWithCollapseAndAggs() {
327336
);
328337
// this one retrieves docs 2 and 6 due to prefilter
329338
StandardRetrieverBuilder standard1 = new StandardRetrieverBuilder(
330-
QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_2", "doc_3", "doc_6")).boost(20L)
339+
QueryBuilders.boolQuery()
340+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_2")).boost(20L))
341+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_3")).boost(10L))
342+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_6")).boost(5L))
331343
);
332344
standard1.getPreFilterQueryBuilders().add(QueryBuilders.queryStringQuery("search").defaultField(TEXT_FIELD));
333345
// this one retrieves docs 2, 3, 6, and 7
@@ -390,7 +402,10 @@ public void testMultipleRRFRetrievers() {
390402
);
391403
// this one retrieves docs 2 and 6 due to prefilter
392404
StandardRetrieverBuilder standard1 = new StandardRetrieverBuilder(
393-
QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_2", "doc_3", "doc_6")).boost(20L)
405+
QueryBuilders.boolQuery()
406+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_2")).boost(20L))
407+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_3")).boost(10L))
408+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_6")).boost(5L))
394409
);
395410
standard1.getPreFilterQueryBuilders().add(QueryBuilders.queryStringQuery("search").defaultField(TEXT_FIELD));
396411
// this one retrieves docs 2, 3, 6, and 7
@@ -453,7 +468,10 @@ public void testRRFExplainWithNamedRetrievers() {
453468
standard0.retrieverName("my_custom_retriever");
454469
// this one retrieves docs 2 and 6 due to prefilter
455470
StandardRetrieverBuilder standard1 = new StandardRetrieverBuilder(
456-
QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_2", "doc_3", "doc_6")).boost(20L)
471+
QueryBuilders.boolQuery()
472+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_2")).boost(20L))
473+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_3")).boost(10L))
474+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_6")).boost(5L))
457475
);
458476
standard1.getPreFilterQueryBuilders().add(QueryBuilders.queryStringQuery("search").defaultField(TEXT_FIELD));
459477
// this one retrieves docs 2, 3, 6, and 7
@@ -509,7 +527,10 @@ public void testRRFExplainWithAnotherNestedRRF() {
509527
standard0.retrieverName("my_custom_retriever");
510528
// this one retrieves docs 2 and 6 due to prefilter
511529
StandardRetrieverBuilder standard1 = new StandardRetrieverBuilder(
512-
QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_2", "doc_3", "doc_6")).boost(20L)
530+
QueryBuilders.boolQuery()
531+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_2")).boost(20L))
532+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_3")).boost(10L))
533+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_6")).boost(5L))
513534
);
514535
standard1.getPreFilterQueryBuilders().add(QueryBuilders.queryStringQuery("search").defaultField(TEXT_FIELD));
515536
// this one retrieves docs 2, 3, 6, and 7
@@ -577,7 +598,10 @@ public void testRRFInnerRetrieverSearchError() {
577598
QueryBuilders.constantScoreQuery(QueryBuilders.rangeQuery(VECTOR_FIELD).gte(10))
578599
);
579600
StandardRetrieverBuilder standard1 = new StandardRetrieverBuilder(
580-
QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_2", "doc_3", "doc_6")).boost(20L)
601+
QueryBuilders.boolQuery()
602+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_2")).boost(20L))
603+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_3")).boost(10L))
604+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_6")).boost(5L))
581605
);
582606
standard1.getPreFilterQueryBuilders().add(QueryBuilders.queryStringQuery("search").defaultField(TEXT_FIELD));
583607
source.retriever(
@@ -613,7 +637,10 @@ public void extractToSearchSourceBuilder(SearchSourceBuilder searchSourceBuilder
613637
}
614638
};
615639
StandardRetrieverBuilder standard1 = new StandardRetrieverBuilder(
616-
QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_2", "doc_3", "doc_6")).boost(20L)
640+
QueryBuilders.boolQuery()
641+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_2")).boost(20L))
642+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_3")).boost(10L))
643+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_6")).boost(5L))
617644
);
618645
standard1.getPreFilterQueryBuilders().add(QueryBuilders.queryStringQuery("search").defaultField(TEXT_FIELD));
619646
source.retriever(
@@ -646,7 +673,10 @@ public void extractToSearchSourceBuilder(SearchSourceBuilder searchSourceBuilder
646673
}
647674
};
648675
StandardRetrieverBuilder standard1 = new StandardRetrieverBuilder(
649-
QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_2", "doc_3", "doc_6")).boost(20L)
676+
QueryBuilders.boolQuery()
677+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_2")).boost(20L))
678+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_3")).boost(10L))
679+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_6")).boost(5L))
650680
);
651681
standard1.getPreFilterQueryBuilders().add(QueryBuilders.queryStringQuery("search").defaultField(TEXT_FIELD));
652682
source.retriever(

x-pack/plugin/rank-rrf/src/internalClusterTest/java/org/elasticsearch/xpack/rank/rrf/RRFRetrieverBuilderNestedDocsIT.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ public void testRRFRetrieverWithNestedQuery() {
142142
);
143143
// this one retrieves docs 2 and 6 due to prefilter
144144
StandardRetrieverBuilder standard1 = new StandardRetrieverBuilder(
145-
QueryBuilders.constantScoreQuery(QueryBuilders.termsQuery(ID_FIELD, "doc_2", "doc_3", "doc_6")).boost(20L)
145+
QueryBuilders.boolQuery()
146+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_2")).boost(20L))
147+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_3")).boost(10L))
148+
.should(QueryBuilders.constantScoreQuery(QueryBuilders.idsQuery().addIds("doc_6")).boost(5L))
146149
);
147150
standard1.getPreFilterQueryBuilders().add(QueryBuilders.queryStringQuery("search").defaultField(TEXT_FIELD));
148151
// this one retrieves docs 6

x-pack/plugin/rank-rrf/src/yamlRestTest/resources/rest-api-spec/test/rrf/700_rrf_retriever_search_api_compatibility.yml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ setup:
1111
body:
1212
mappings:
1313
properties:
14+
id:
15+
type: integer
1416
text:
1517
type: text
1618
text_to_highlight:
@@ -39,6 +41,7 @@ setup:
3941
index: test
4042
id: "1"
4143
body:
44+
id: 1
4245
text: "term1"
4346
vector: [1.0]
4447

@@ -47,6 +50,7 @@ setup:
4750
index: test
4851
id: "2"
4952
body:
53+
id: 2
5054
text: "term2"
5155
text_to_highlight: "search for the truth"
5256
keyword: "biology"
@@ -57,6 +61,7 @@ setup:
5761
index: test
5862
id: "3"
5963
body:
64+
id: 3
6065
text: "term3"
6166
text_to_highlight: "nothing related"
6267
keyword: "technology"
@@ -67,23 +72,26 @@ setup:
6772
index: test
6873
id: "4"
6974
body:
75+
id: 4
7076
text: "term4"
7177
vector: [4.0]
7278
- do:
7379
index:
7480
index: test
7581
id: "5"
7682
body:
83+
id: 5
7784
text: "term5"
7885
text_to_highlight: "You know, for Search!"
7986
keyword: "technology"
8087
integer: 5
8188
vector: [5.0]
8289
- do:
8390
index:
91+
id: 6
8492
index: test
85-
id: "6"
8693
body:
94+
id: 6
8795
text: "term6"
8896
keyword: "biology"
8997
integer: 6
@@ -93,6 +101,7 @@ setup:
93101
index: test
94102
id: "7"
95103
body:
104+
id: 7
96105
text: "term7"
97106
keyword: "astronomy"
98107
vector: [77.0]
@@ -102,6 +111,7 @@ setup:
102111
index: test
103112
id: "8"
104113
body:
114+
id: 8
105115
text: "term8"
106116
keyword: "technology"
107117
nested: { views: 100}
@@ -110,6 +120,7 @@ setup:
110120
index: test
111121
id: "9"
112122
body:
123+
id: 9
113124
text: "term9"
114125
integer: 2
115126
keyword: "technology"
@@ -439,7 +450,19 @@ setup:
439450
rank_window_size: 5
440451
rank_constant: 10
441452
size: 3
442-
collapse: { field: keyword, inner_hits: { name: sub_hits, size: 2 } }
453+
collapse: {
454+
field: keyword,
455+
inner_hits: {
456+
name: sub_hits,
457+
size: 2,
458+
sort:
459+
{
460+
id: {
461+
order: desc
462+
}
463+
}
464+
}
465+
}
443466

444467
- match: { hits.total : 9 }
445468

@@ -456,8 +479,8 @@ setup:
456479

457480
- match: { hits.hits.1.inner_hits.sub_hits.hits.total : 4 }
458481
- length: { hits.hits.1.inner_hits.sub_hits.hits.hits : 2 }
459-
- match: { hits.hits.1.inner_hits.sub_hits.hits.hits.0._id: "5" }
460-
- match: { hits.hits.1.inner_hits.sub_hits.hits.hits.1._id: "3" }
482+
- match: { hits.hits.1.inner_hits.sub_hits.hits.hits.0._id: "9" }
483+
- match: { hits.hits.1.inner_hits.sub_hits.hits.hits.1._id: "8" }
461484

462485
- length: { hits.hits.2.inner_hits.sub_hits.hits.hits: 2 }
463486
- match: { hits.hits.2.inner_hits.sub_hits.hits.hits.0._id: "6" }

x-pack/plugin/rank-rrf/src/yamlRestTest/resources/rest-api-spec/test/rrf/800_rrf_with_text_similarity_reranker_retriever.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ setup:
125125
term: {
126126
topic: "science"
127127
}
128+
},
129+
"sort": {
130+
"integer": "asc"
128131
}
129132
}
130133
},
@@ -303,6 +306,9 @@ setup:
303306
term: {
304307
topic: "science"
305308
}
309+
},
310+
"sort": {
311+
"integer": "asc"
306312
}
307313
}
308314
},

0 commit comments

Comments
 (0)