@@ -515,3 +515,65 @@ def test_update_from_dict():
515
515
"indices_boost" : [{"important-documents" : 2 }],
516
516
"_source" : ["id" , "name" ],
517
517
} == s .to_dict ()
518
+
519
+
520
+ def test_rescore_query_to_dict ():
521
+ s = search .Search (index = "index-name" )
522
+
523
+ positive_query = Q (
524
+ "function_score" ,
525
+ query = Q ("term" , tags = "a" ),
526
+ script_score = {"script" : "_score * 1" },
527
+ )
528
+
529
+ negative_query = Q (
530
+ "function_score" ,
531
+ query = Q ("term" , tags = "b" ),
532
+ script_score = {"script" : "_score * -100" },
533
+ )
534
+
535
+ s = s .query (positive_query )
536
+ s = s .extra (
537
+ rescore = {"window_size" : 100 , "query" : {"rescore_query" : negative_query }}
538
+ )
539
+ assert s .to_dict () == {
540
+ "query" : {
541
+ "function_score" : {
542
+ "query" : {"term" : {"tags" : "a" }},
543
+ "functions" : [{"script_score" : {"script" : "_score * 1" }}],
544
+ }
545
+ },
546
+ "rescore" : {
547
+ "window_size" : 100 ,
548
+ "query" : {
549
+ "rescore_query" : {
550
+ "function_score" : {
551
+ "query" : {"term" : {"tags" : "b" }},
552
+ "functions" : [{"script_score" : {"script" : "_score * -100" }}],
553
+ }
554
+ }
555
+ },
556
+ },
557
+ }
558
+
559
+ assert s .to_dict (
560
+ rescore = {"window_size" : 10 , "query" : {"rescore_query" : positive_query }}
561
+ ) == {
562
+ "query" : {
563
+ "function_score" : {
564
+ "query" : {"term" : {"tags" : "a" }},
565
+ "functions" : [{"script_score" : {"script" : "_score * 1" }}],
566
+ }
567
+ },
568
+ "rescore" : {
569
+ "window_size" : 10 ,
570
+ "query" : {
571
+ "rescore_query" : {
572
+ "function_score" : {
573
+ "query" : {"term" : {"tags" : "a" }},
574
+ "functions" : [{"script_score" : {"script" : "_score * 1" }}],
575
+ }
576
+ }
577
+ },
578
+ },
579
+ }
0 commit comments