45
45
import org .elasticsearch .common .xcontent .ToXContent ;
46
46
import org .elasticsearch .common .xcontent .XContentHelper ;
47
47
import org .elasticsearch .common .xcontent .XContentType ;
48
- import org .elasticsearch .index .query .MatchPhraseQueryBuilder ;
49
48
import org .elasticsearch .index .query .QueryBuilders ;
50
49
import org .elasticsearch .index .query .functionscore .FunctionScoreQueryBuilder ;
51
50
import org .elasticsearch .index .query .functionscore .FunctionScoreQueryBuilder .FilterFunctionBuilder ;
52
51
import org .elasticsearch .index .query .functionscore .GaussDecayFunctionBuilder ;
53
- import org .elasticsearch .index .query .functionscore .ScriptScoreQueryBuilder ;
54
52
import org .json .JSONException ;
55
53
import org .junit .jupiter .api .BeforeAll ;
56
54
import org .junit .jupiter .api .DisplayName ;
@@ -522,37 +520,24 @@ private String requestToString(ToXContent request) throws IOException {
522
520
return XContentHelper .toXContent (request , XContentType .JSON , true ).utf8ToString ();
523
521
}
524
522
525
- @ Test
523
+ @ Test // #1686
526
524
void shouldBuildSearchWithRescorerQuery () throws JSONException {
527
525
CriteriaQuery query = new CriteriaQuery (new Criteria ("lastName" ).is ("Smith" ));
528
- RescorerQuery rescorerQuery = new RescorerQuery ( new NativeSearchQueryBuilder () //
529
- .withQuery (
530
- QueryBuilders .functionScoreQuery (new FunctionScoreQueryBuilder .FilterFunctionBuilder []{
526
+ RescorerQuery rescorerQuery = new RescorerQuery (new NativeSearchQueryBuilder () //
527
+ .withQuery (QueryBuilders
528
+ .functionScoreQuery (new FunctionScoreQueryBuilder .FilterFunctionBuilder [] {
531
529
new FilterFunctionBuilder (QueryBuilders .existsQuery ("someField" ),
532
- new GaussDecayFunctionBuilder ("someField" , 0 , 100000.0 , null , 0.683 )
533
- .setWeight (5.022317f )),
530
+ new GaussDecayFunctionBuilder ("someField" , 0 , 100000.0 , null , 0.683 ).setWeight (5.022317f )),
534
531
new FilterFunctionBuilder (QueryBuilders .existsQuery ("anotherField" ),
535
532
new GaussDecayFunctionBuilder ("anotherField" , "202102" , "31536000s" , null , 0.683 )
536
- .setWeight (4.170836f ))})
537
- .scoreMode (FunctionScoreQuery .ScoreMode .SUM )
538
- .maxBoost (50.0f )
539
- .boostMode (CombineFunction .AVG )
540
- .boost (1.5f ))
541
- .build ()
542
- )
543
- .withWindowSize (50 )
544
- .withQueryWeight (2.0f )
545
- .withRescoreQueryWeight (5.0f )
546
- .withScoreMode (ScoreMode .Multiply );
533
+ .setWeight (4.170836f )) })
534
+ .scoreMode (FunctionScoreQuery .ScoreMode .SUM ).maxBoost (50.0f ).boostMode (CombineFunction .AVG ).boost (1.5f ))
535
+ .build ()).withWindowSize (50 ).withQueryWeight (2.0f ).withRescoreQueryWeight (5.0f )
536
+ .withScoreMode (ScoreMode .Multiply );
547
537
548
538
RescorerQuery anotherRescorerQuery = new RescorerQuery (new NativeSearchQueryBuilder () //
549
- .withQuery (
550
- QueryBuilders .matchPhraseQuery ("message" , "the quick brown" ).slop (2 ))
551
- .build ()
552
- )
553
- .withWindowSize (100 )
554
- .withQueryWeight (0.7f )
555
- .withRescoreQueryWeight (1.2f );
539
+ .withQuery (QueryBuilders .matchPhraseQuery ("message" , "the quick brown" ).slop (2 )).build ()).withWindowSize (100 )
540
+ .withQueryWeight (0.7f ).withRescoreQueryWeight (1.2f );
556
541
557
542
query .addRescorerQuery (rescorerQuery );
558
543
query .addRescorerQuery (anotherRescorerQuery );
@@ -574,79 +559,40 @@ void shouldBuildSearchWithRescorerQuery() throws JSONException {
574
559
" ]" + //
575
560
" }" + //
576
561
" }," + //
577
- " \" rescore\" : [{\n "
578
- + " \" window_size\" : 100,\n "
579
- + " \" query\" : {\n "
580
- + " \" rescore_query\" : {\n "
581
- + " \" match_phrase\" : {\n "
582
- + " \" message\" : {\n "
583
- + " \" query\" : \" the quick brown\" ,\n "
584
- + " \" slop\" : 2\n "
585
- + " }\n "
586
- + " }\n "
587
- + " },\n "
588
- + " \" query_weight\" : 0.7,\n "
589
- + " \" rescore_query_weight\" : 1.2\n "
590
- + " }\n "
591
- + " },"
592
- + " {\n "
593
- + " \" window_size\" : 50,\n "
594
- + " \" query\" : {\n "
595
- + " \" rescore_query\" : {\n "
596
- + " \" function_score\" : {\n "
597
- + " \" query\" : {\n "
598
- + " \" match_all\" : {\n "
599
- + " \" boost\" : 1.0\n "
600
- + " }\n "
601
- + " },\n "
602
- + " \" functions\" : [\n "
603
- + " {\n "
604
- + " \" filter\" : {\n "
562
+ " \" rescore\" : [{\n " + " \" window_size\" : 100,\n " + " \" query\" : {\n "
563
+ + " \" rescore_query\" : {\n " + " \" match_phrase\" : {\n " + " \" message\" : {\n "
564
+ + " \" query\" : \" the quick brown\" ,\n " + " \" slop\" : 2\n "
565
+ + " }\n " + " }\n " + " },\n " + " \" query_weight\" : 0.7,\n "
566
+ + " \" rescore_query_weight\" : 1.2\n " + " }\n " + " }," + " {\n " + " \" window_size\" : 50,\n "
567
+ + " \" query\" : {\n " + " \" rescore_query\" : {\n " + " \" function_score\" : {\n "
568
+ + " \" query\" : {\n " + " \" match_all\" : {\n "
569
+ + " \" boost\" : 1.0\n " + " }\n "
570
+ + " },\n " + " \" functions\" : [\n "
571
+ + " {\n " + " \" filter\" : {\n "
605
572
+ " \" exists\" : {\n "
606
573
+ " \" field\" : \" someField\" ,\n "
607
- + " \" boost\" : 1.0\n "
608
- + " }\n "
609
- + " },\n "
610
- + " \" weight\" : 5.022317,\n "
611
- + " \" gauss\" : {\n "
612
- + " \" someField\" : {\n "
574
+ + " \" boost\" : 1.0\n " + " }\n "
575
+ + " },\n " + " \" weight\" : 5.022317,\n "
576
+ + " \" gauss\" : {\n " + " \" someField\" : {\n "
613
577
+ " \" origin\" : 0.0,\n "
614
578
+ " \" scale\" : 100000.0,\n "
615
- + " \" decay\" : 0.683\n "
616
- + " },\n "
617
- + " \" multi_value_mode\" : \" MIN\" \n "
618
- + " }\n "
619
- + " },\n "
620
- + " {\n "
621
- + " \" filter\" : {\n "
622
- + " \" exists\" : {\n "
579
+ + " \" decay\" : 0.683\n " + " },\n "
580
+ + " \" multi_value_mode\" : \" MIN\" \n " + " }\n "
581
+ + " },\n " + " {\n "
582
+ + " \" filter\" : {\n " + " \" exists\" : {\n "
623
583
+ " \" field\" : \" anotherField\" ,\n "
624
- + " \" boost\" : 1.0\n "
625
- + " }\n "
626
- + " },\n "
627
- + " \" weight\" : 4.170836,\n "
628
- + " \" gauss\" : {\n "
629
- + " \" anotherField\" : {\n "
584
+ + " \" boost\" : 1.0\n " + " }\n "
585
+ + " },\n " + " \" weight\" : 4.170836,\n "
586
+ + " \" gauss\" : {\n " + " \" anotherField\" : {\n "
630
587
+ " \" origin\" : \" 202102\" ,\n "
631
588
+ " \" scale\" : \" 31536000s\" ,\n "
632
- + " \" decay\" : 0.683\n "
633
- + " },\n "
634
- + " \" multi_value_mode\" : \" MIN\" \n "
635
- + " }\n "
636
- + " }\n "
637
- + " ],\n "
638
- + " \" score_mode\" : \" sum\" ,\n "
639
- + " \" boost_mode\" : \" avg\" ,\n "
640
- + " \" max_boost\" : 50.0,\n "
641
- + " \" boost\" : 1.5\n "
642
- + " }\n "
643
- + " },\n "
644
- + " \" query_weight\" : 2.0,"
645
- + " \" rescore_query_weight\" : 5.0,"
646
- + " \" score_mode\" : \" multiply\" "
647
- + " }\n "
648
- + " }\n "
649
- + " ]\n "
589
+ + " \" decay\" : 0.683\n " + " },\n "
590
+ + " \" multi_value_mode\" : \" MIN\" \n " + " }\n "
591
+ + " }\n " + " ],\n "
592
+ + " \" score_mode\" : \" sum\" ,\n " + " \" boost_mode\" : \" avg\" ,\n "
593
+ + " \" max_boost\" : 50.0,\n " + " \" boost\" : 1.5\n "
594
+ + " }\n " + " },\n " + " \" query_weight\" : 2.0,"
595
+ + " \" rescore_query_weight\" : 5.0," + " \" score_mode\" : \" multiply\" " + " }\n " + " }\n " + " ]\n "
650
596
+ '}' ;
651
597
652
598
String searchRequest = requestFactory .searchRequest (query , Person .class , IndexCoordinates .of ("persons" )).source ()
0 commit comments