@@ -18,6 +18,13 @@ declare namespace esb {
1818 */
1919 query ( query : Query ) : this;
2020
21+ /**
22+ * Sets knn on the request body.
23+ *
24+ * @param {KNN|KNN[] } knn
25+ */
26+ kNN ( knn : KNN | KNN [ ] ) : this;
27+
2128 /**
2229 * Sets aggregation on the request body.
2330 * Alias for method `aggregation`
@@ -3141,7 +3148,7 @@ declare namespace esb {
31413148
31423149 /**
31433150 * Sets the script used to compute the score of documents returned by the query.
3144- *
3151+ *
31453152 * @param {Script } script A valid `Script` object
31463153 */
31473154 script ( script : Script ) : this;
@@ -3761,6 +3768,84 @@ declare namespace esb {
37613768 spanQry ?: SpanQueryBase
37623769 ) : SpanFieldMaskingQuery ;
37633770
3771+ /**
3772+ * Knn performs k-nearest neighbor (KNN) searches.
3773+ * This class allows configuring the KNN search with various parameters such as field, query vector,
3774+ * number of nearest neighbors (k), number of candidates, boost factor, and similarity metric.
3775+ *
3776+ * NOTE: Only available in Elasticsearch v8.0+
3777+ */
3778+ export class KNN {
3779+ /**
3780+ * Creates an instance of Knn, initializing the internal state for the k-NN search.
3781+ *
3782+ * @param {string } field - (Optional) The field against which to perform the k-NN search.
3783+ * @param {number } k - (Optional) The number of nearest neighbors to retrieve.
3784+ * @param {number } numCandidates - (Optional) The number of candidate neighbors to consider during the search.
3785+ * @throws {Error } If the number of candidates (numCandidates) is less than the number of neighbors (k).
3786+ */
3787+ constructor ( field : string , k : number , numCandidates : number ) ;
3788+
3789+ /**
3790+ * Sets the query vector for the KNN search, an array of numbers representing the reference point.
3791+ *
3792+ * @param {number[] } vector
3793+ */
3794+ queryVector ( vector : number [ ] ) : this;
3795+
3796+ /**
3797+ * Sets the query vector builder for the k-NN search.
3798+ * This method configures a query vector builder using a specified model ID and model text.
3799+ * Note that either a direct query vector or a query vector builder can be provided, but not both.
3800+ *
3801+ * @param {string } modelId - The ID of the model used for generating the query vector.
3802+ * @param {string } modelText - The text input based on which the query vector is generated.
3803+ * @returns {KNN } Returns the instance of Knn for method chaining.
3804+ * @throws {Error } If both query_vector_builder and query_vector are provided.
3805+ */
3806+ queryVectorBuilder ( modelId : string , modelText : string ) : this;
3807+
3808+ /**
3809+ * Adds one or more filter queries to the k-NN search.
3810+ * This method is designed to apply filters to the k-NN search. It accepts either a single
3811+ * query or an array of queries. Each query acts as a filter, refining the search results
3812+ * according to the specified conditions. These queries must be instances of the `Query` class.
3813+ *
3814+ * @param {Query|Query[] } queries - A single `Query` instance or an array of `Query` instances for filtering.
3815+ * @returns {KNN } Returns `this` to allow method chaining.
3816+ * @throws {TypeError } If any of the provided queries is not an instance of `Query`.
3817+ */
3818+ filter ( queries : Query | Query [ ] ) : this;
3819+
3820+ /**
3821+ * Applies a boost factor to the query to influence the relevance score of returned documents.
3822+ *
3823+ * @param {number } boost
3824+ */
3825+ boost ( boost : number ) : this;
3826+
3827+ /**
3828+ * Sets the similarity metric used in the KNN algorithm to calculate similarity.
3829+ *
3830+ * @param {number } similarity
3831+ */
3832+ similarity ( similarity : number ) : this;
3833+
3834+ /**
3835+ * Override default `toJSON` to return DSL representation for the `query`
3836+ *
3837+ * @override
3838+ */
3839+ toJSON ( ) : object ;
3840+ }
3841+
3842+ /**
3843+ * Factory function to instantiate a new Knn object.
3844+ *
3845+ * @returns {KNN }
3846+ */
3847+ export function kNN ( field : string , k : number , numCandidates : number ) : KNN ;
3848+
37643849 /**
37653850 * Base class implementation for all aggregation types.
37663851 *
@@ -3913,9 +3998,9 @@ declare namespace esb {
39133998 /**
39143999 * A single-value metrics aggregation that computes the weighted average of numeric values that are extracted from the aggregated documents.
39154000 * These values can be extracted either from specific numeric fields in the documents.
3916- *
4001+ *
39174002 * [Elasticsearch reference](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-weight-avg-aggregation.html)
3918- *
4003+ *
39194004 * Added in Elasticsearch v6.4.0
39204005 * [Release notes](https://www.elastic.co/guide/en/elasticsearch/reference/6.4/release-notes-6.4.0.html)
39214006 *
@@ -3929,7 +4014,7 @@ declare namespace esb {
39294014
39304015 /**
39314016 * Sets the value
3932- *
4017+ *
39334018 * @param {string | Script } value Field name or script to be used as the value
39344019 * @param {number= } missing Sets the missing parameter which defines how documents
39354020 * that are missing a value should be treated.
@@ -3939,7 +4024,7 @@ declare namespace esb {
39394024
39404025 /**
39414026 * Sets the weight
3942- *
4027+ *
39434028 * @param {string | Script } weight Field name or script to be used as the weight
39444029 * @param {number= } missing Sets the missing parameter which defines how documents
39454030 * that are missing a value should be treated.
@@ -3969,9 +4054,9 @@ declare namespace esb {
39694054 /**
39704055 * A single-value metrics aggregation that computes the weighted average of numeric values that are extracted from the aggregated documents.
39714056 * These values can be extracted either from specific numeric fields in the documents.
3972- *
4057+ *
39734058 * [Elasticsearch reference](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-weight-avg-aggregation.html)
3974- *
4059+ *
39754060 * Added in Elasticsearch v6.4.0
39764061 * [Release notes](https://www.elastic.co/guide/en/elasticsearch/reference/6.4/release-notes-6.4.0.html)
39774062 *
@@ -8922,15 +9007,15 @@ declare namespace esb {
89229007
89239008 /**
89249009 * Sets the type of the runtime field.
8925- *
9010+ *
89269011 * @param {string } type One of `boolean`, `composite`, `date`, `double`, `geo_point`, `ip`, `keyword`, `long`, `lookup`.
89279012 * @returns {void }
89289013 */
89299014 type ( type : 'boolean' | 'composite' | 'date' | 'double' | 'geo_point' | 'ip' | 'keyword' | 'long' | 'lookup' ) : void ;
89309015
89319016 /**
89329017 * Sets the source of the script.
8933- *
9018+ *
89349019 * @param {string } script
89359020 * @returns {void }
89369021 */
0 commit comments