@@ -181,6 +181,12 @@ public override SearchRequest Read(ref Utf8JsonReader reader, Type typeToConvert
181
181
continue ;
182
182
}
183
183
184
+ if ( property == "knn" )
185
+ {
186
+ variant . Knn = JsonSerializer . Deserialize < Elastic . Clients . Elasticsearch . KnnQuery ? > ( ref reader , options ) ;
187
+ continue ;
188
+ }
189
+
184
190
if ( property == "min_score" )
185
191
{
186
192
variant . MinScore = JsonSerializer . Deserialize < double ? > ( ref reader , options ) ;
@@ -375,6 +381,12 @@ public override void Write(Utf8JsonWriter writer, SearchRequest value, JsonSeria
375
381
JsonSerializer . Serialize ( writer , value . DocvalueFields , options ) ;
376
382
}
377
383
384
+ if ( value . Knn is not null )
385
+ {
386
+ writer . WritePropertyName ( "knn" ) ;
387
+ JsonSerializer . Serialize ( writer , value . Knn , options ) ;
388
+ }
389
+
378
390
if ( value . MinScore . HasValue )
379
391
{
380
392
writer . WritePropertyName ( "min_score" ) ;
@@ -648,6 +660,10 @@ public SearchRequest(Elastic.Clients.Elasticsearch.Indices? indices) : base(r =>
648
660
[ JsonPropertyName ( "docvalue_fields" ) ]
649
661
public IEnumerable < Elastic . Clients . Elasticsearch . QueryDsl . FieldAndFormat > ? DocvalueFields { get ; set ; }
650
662
663
+ [ JsonInclude ]
664
+ [ JsonPropertyName ( "knn" ) ]
665
+ public Elastic . Clients . Elasticsearch . KnnQuery ? Knn { get ; set ; }
666
+
651
667
[ JsonInclude ]
652
668
[ JsonPropertyName ( "min_score" ) ]
653
669
public double ? MinScore { get ; set ; }
@@ -828,6 +844,12 @@ public SearchRequestDescriptor<TDocument> Indices(Elastic.Clients.Elasticsearch.
828
844
829
845
private Action < HighlightDescriptor < TDocument > > HighlightDescriptorAction { get ; set ; }
830
846
847
+ private Elastic . Clients . Elasticsearch . KnnQuery ? KnnValue { get ; set ; }
848
+
849
+ private KnnQueryDescriptor < TDocument > KnnDescriptor { get ; set ; }
850
+
851
+ private Action < KnnQueryDescriptor < TDocument > > KnnDescriptorAction { get ; set ; }
852
+
831
853
private Elastic . Clients . Elasticsearch . QueryDsl . QueryContainer ? PostFilterValue { get ; set ; }
832
854
833
855
private QueryDsl . QueryContainerDescriptor < TDocument > PostFilterDescriptor { get ; set ; }
@@ -1050,6 +1072,30 @@ public SearchRequestDescriptor<TDocument> Highlight(Action<HighlightDescriptor<T
1050
1072
return Self ;
1051
1073
}
1052
1074
1075
+ public SearchRequestDescriptor < TDocument > Knn ( Elastic . Clients . Elasticsearch . KnnQuery ? knn )
1076
+ {
1077
+ KnnDescriptor = null ;
1078
+ KnnDescriptorAction = null ;
1079
+ KnnValue = knn ;
1080
+ return Self ;
1081
+ }
1082
+
1083
+ public SearchRequestDescriptor < TDocument > Knn ( KnnQueryDescriptor < TDocument > descriptor )
1084
+ {
1085
+ KnnValue = null ;
1086
+ KnnDescriptorAction = null ;
1087
+ KnnDescriptor = descriptor ;
1088
+ return Self ;
1089
+ }
1090
+
1091
+ public SearchRequestDescriptor < TDocument > Knn ( Action < KnnQueryDescriptor < TDocument > > configure )
1092
+ {
1093
+ KnnValue = null ;
1094
+ KnnDescriptor = null ;
1095
+ KnnDescriptorAction = configure ;
1096
+ return Self ;
1097
+ }
1098
+
1053
1099
public SearchRequestDescriptor < TDocument > PostFilter ( Elastic . Clients . Elasticsearch . QueryDsl . QueryContainer ? postFilter )
1054
1100
{
1055
1101
PostFilterDescriptor = null ;
@@ -1445,6 +1491,22 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o
1445
1491
JsonSerializer . Serialize ( writer , HighlightValue , options ) ;
1446
1492
}
1447
1493
1494
+ if ( KnnDescriptor is not null )
1495
+ {
1496
+ writer . WritePropertyName ( "knn" ) ;
1497
+ JsonSerializer . Serialize ( writer , KnnDescriptor , options ) ;
1498
+ }
1499
+ else if ( KnnDescriptorAction is not null )
1500
+ {
1501
+ writer . WritePropertyName ( "knn" ) ;
1502
+ JsonSerializer . Serialize ( writer , new KnnQueryDescriptor < TDocument > ( KnnDescriptorAction ) , options ) ;
1503
+ }
1504
+ else if ( KnnValue is not null )
1505
+ {
1506
+ writer . WritePropertyName ( "knn" ) ;
1507
+ JsonSerializer . Serialize ( writer , KnnValue , options ) ;
1508
+ }
1509
+
1448
1510
if ( PostFilterDescriptor is not null )
1449
1511
{
1450
1512
writer . WritePropertyName ( "post_filter" ) ;
@@ -1763,6 +1825,12 @@ public SearchRequestDescriptor Indices(Elastic.Clients.Elasticsearch.Indices? in
1763
1825
1764
1826
private Action < HighlightDescriptor > HighlightDescriptorAction { get ; set ; }
1765
1827
1828
+ private Elastic . Clients . Elasticsearch . KnnQuery ? KnnValue { get ; set ; }
1829
+
1830
+ private KnnQueryDescriptor KnnDescriptor { get ; set ; }
1831
+
1832
+ private Action < KnnQueryDescriptor > KnnDescriptorAction { get ; set ; }
1833
+
1766
1834
private Elastic . Clients . Elasticsearch . QueryDsl . QueryContainer ? PostFilterValue { get ; set ; }
1767
1835
1768
1836
private QueryDsl . QueryContainerDescriptor PostFilterDescriptor { get ; set ; }
@@ -1985,6 +2053,30 @@ public SearchRequestDescriptor Highlight(Action<HighlightDescriptor> configure)
1985
2053
return Self ;
1986
2054
}
1987
2055
2056
+ public SearchRequestDescriptor Knn ( Elastic . Clients . Elasticsearch . KnnQuery ? knn )
2057
+ {
2058
+ KnnDescriptor = null ;
2059
+ KnnDescriptorAction = null ;
2060
+ KnnValue = knn ;
2061
+ return Self ;
2062
+ }
2063
+
2064
+ public SearchRequestDescriptor Knn ( KnnQueryDescriptor descriptor )
2065
+ {
2066
+ KnnValue = null ;
2067
+ KnnDescriptorAction = null ;
2068
+ KnnDescriptor = descriptor ;
2069
+ return Self ;
2070
+ }
2071
+
2072
+ public SearchRequestDescriptor Knn ( Action < KnnQueryDescriptor > configure )
2073
+ {
2074
+ KnnValue = null ;
2075
+ KnnDescriptor = null ;
2076
+ KnnDescriptorAction = configure ;
2077
+ return Self ;
2078
+ }
2079
+
1988
2080
public SearchRequestDescriptor PostFilter ( Elastic . Clients . Elasticsearch . QueryDsl . QueryContainer ? postFilter )
1989
2081
{
1990
2082
PostFilterDescriptor = null ;
@@ -2386,6 +2478,22 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o
2386
2478
JsonSerializer . Serialize ( writer , HighlightValue , options ) ;
2387
2479
}
2388
2480
2481
+ if ( KnnDescriptor is not null )
2482
+ {
2483
+ writer . WritePropertyName ( "knn" ) ;
2484
+ JsonSerializer . Serialize ( writer , KnnDescriptor , options ) ;
2485
+ }
2486
+ else if ( KnnDescriptorAction is not null )
2487
+ {
2488
+ writer . WritePropertyName ( "knn" ) ;
2489
+ JsonSerializer . Serialize ( writer , new KnnQueryDescriptor ( KnnDescriptorAction ) , options ) ;
2490
+ }
2491
+ else if ( KnnValue is not null )
2492
+ {
2493
+ writer . WritePropertyName ( "knn" ) ;
2494
+ JsonSerializer . Serialize ( writer , KnnValue , options ) ;
2495
+ }
2496
+
2389
2497
if ( PostFilterDescriptor is not null )
2390
2498
{
2391
2499
writer . WritePropertyName ( "post_filter" ) ;
0 commit comments