@@ -181,6 +181,12 @@ public override SearchRequest Read(ref Utf8JsonReader reader, Type typeToConvert
181181 continue ;
182182 }
183183
184+ if ( property == "knn" )
185+ {
186+ variant . Knn = JsonSerializer . Deserialize < Elastic . Clients . Elasticsearch . KnnQuery ? > ( ref reader , options ) ;
187+ continue ;
188+ }
189+
184190 if ( property == "min_score" )
185191 {
186192 variant . MinScore = JsonSerializer . Deserialize < double ? > ( ref reader , options ) ;
@@ -375,6 +381,12 @@ public override void Write(Utf8JsonWriter writer, SearchRequest value, JsonSeria
375381 JsonSerializer . Serialize ( writer , value . DocvalueFields , options ) ;
376382 }
377383
384+ if ( value . Knn is not null )
385+ {
386+ writer . WritePropertyName ( "knn" ) ;
387+ JsonSerializer . Serialize ( writer , value . Knn , options ) ;
388+ }
389+
378390 if ( value . MinScore . HasValue )
379391 {
380392 writer . WritePropertyName ( "min_score" ) ;
@@ -648,6 +660,10 @@ public SearchRequest(Elastic.Clients.Elasticsearch.Indices? indices) : base(r =>
648660 [ JsonPropertyName ( "docvalue_fields" ) ]
649661 public IEnumerable < Elastic . Clients . Elasticsearch . QueryDsl . FieldAndFormat > ? DocvalueFields { get ; set ; }
650662
663+ [ JsonInclude ]
664+ [ JsonPropertyName ( "knn" ) ]
665+ public Elastic . Clients . Elasticsearch . KnnQuery ? Knn { get ; set ; }
666+
651667 [ JsonInclude ]
652668 [ JsonPropertyName ( "min_score" ) ]
653669 public double ? MinScore { get ; set ; }
@@ -828,6 +844,12 @@ public SearchRequestDescriptor<TDocument> Indices(Elastic.Clients.Elasticsearch.
828844
829845 private Action < HighlightDescriptor < TDocument > > HighlightDescriptorAction { get ; set ; }
830846
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+
831853 private Elastic . Clients . Elasticsearch . QueryDsl . QueryContainer ? PostFilterValue { get ; set ; }
832854
833855 private QueryDsl . QueryContainerDescriptor < TDocument > PostFilterDescriptor { get ; set ; }
@@ -1050,6 +1072,30 @@ public SearchRequestDescriptor<TDocument> Highlight(Action<HighlightDescriptor<T
10501072 return Self ;
10511073 }
10521074
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+
10531099 public SearchRequestDescriptor < TDocument > PostFilter ( Elastic . Clients . Elasticsearch . QueryDsl . QueryContainer ? postFilter )
10541100 {
10551101 PostFilterDescriptor = null ;
@@ -1445,6 +1491,22 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o
14451491 JsonSerializer . Serialize ( writer , HighlightValue , options ) ;
14461492 }
14471493
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+
14481510 if ( PostFilterDescriptor is not null )
14491511 {
14501512 writer . WritePropertyName ( "post_filter" ) ;
@@ -1763,6 +1825,12 @@ public SearchRequestDescriptor Indices(Elastic.Clients.Elasticsearch.Indices? in
17631825
17641826 private Action < HighlightDescriptor > HighlightDescriptorAction { get ; set ; }
17651827
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+
17661834 private Elastic . Clients . Elasticsearch . QueryDsl . QueryContainer ? PostFilterValue { get ; set ; }
17671835
17681836 private QueryDsl . QueryContainerDescriptor PostFilterDescriptor { get ; set ; }
@@ -1985,6 +2053,30 @@ public SearchRequestDescriptor Highlight(Action<HighlightDescriptor> configure)
19852053 return Self ;
19862054 }
19872055
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+
19882080 public SearchRequestDescriptor PostFilter ( Elastic . Clients . Elasticsearch . QueryDsl . QueryContainer ? postFilter )
19892081 {
19902082 PostFilterDescriptor = null ;
@@ -2386,6 +2478,22 @@ protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions o
23862478 JsonSerializer . Serialize ( writer , HighlightValue , options ) ;
23872479 }
23882480
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+
23892497 if ( PostFilterDescriptor is not null )
23902498 {
23912499 writer . WritePropertyName ( "post_filter" ) ;
0 commit comments