Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@
import co.elastic.clients.elasticsearch.core.IndexResponse;
import co.elastic.clients.elasticsearch.core.InfoRequest;
import co.elastic.clients.elasticsearch.core.InfoResponse;
import co.elastic.clients.elasticsearch.core.KnnSearchRequest;
import co.elastic.clients.elasticsearch.core.KnnSearchResponse;
import co.elastic.clients.elasticsearch.core.MgetRequest;
import co.elastic.clients.elasticsearch.core.MgetResponse;
import co.elastic.clients.elasticsearch.core.MsearchRequest;
Expand Down Expand Up @@ -3282,207 +3280,6 @@ public CompletableFuture<InfoResponse> info() {
return this.transport.performRequestAsync(InfoRequest._INSTANCE, InfoRequest._ENDPOINT, this.transportOptions);
}

// ----- Endpoint: knn_search

/**
* Run a knn search.
* <p>
* NOTE: The kNN search API has been replaced by the <code>knn</code> option in
* the search API.
* <p>
* Perform a k-nearest neighbor (kNN) search on a dense_vector field and return
* the matching documents. Given a query vector, the API finds the k closest
* vectors and returns those documents as search hits.
* <p>
* Elasticsearch uses the HNSW algorithm to support efficient kNN search. Like
* most kNN algorithms, HNSW is an approximate method that sacrifices result
* accuracy for improved search speed. This means the results returned are not
* always the true k closest neighbors.
* <p>
* The kNN search API supports restricting the search using a filter. The search
* will return the top k documents that also match the filter query.
* <p>
* A kNN search response has the exact same structure as a search API response.
* However, certain sections have a meaning specific to kNN search:
* <ul>
* <li>The document <code>_score</code> is determined by the similarity between
* the query and document vector.</li>
* <li>The <code>hits.total</code> object contains the total number of nearest
* neighbor candidates considered, which is
* <code>num_candidates * num_shards</code>. The
* <code>hits.total.relation</code> will always be <code>eq</code>, indicating
* an exact value.</li>
* </ul>
*
* @see <a href=
* "https://www.elastic.co/guide/en/elasticsearch/reference/8.19/knn-search-api.html">Documentation
* on elastic.co</a>
*/

public <TDocument> CompletableFuture<KnnSearchResponse<TDocument>> knnSearch(KnnSearchRequest request,
Class<TDocument> tDocumentClass) {
@SuppressWarnings("unchecked")
JsonEndpoint<KnnSearchRequest, KnnSearchResponse<TDocument>, ErrorResponse> endpoint = (JsonEndpoint<KnnSearchRequest, KnnSearchResponse<TDocument>, ErrorResponse>) KnnSearchRequest._ENDPOINT;
endpoint = new EndpointWithResponseMapperAttr<>(endpoint,
"co.elastic.clients:Deserializer:_global.knn_search.Response.TDocument",
getDeserializer(tDocumentClass));

return this.transport.performRequestAsync(request, endpoint, this.transportOptions);
}

/**
* Run a knn search.
* <p>
* NOTE: The kNN search API has been replaced by the <code>knn</code> option in
* the search API.
* <p>
* Perform a k-nearest neighbor (kNN) search on a dense_vector field and return
* the matching documents. Given a query vector, the API finds the k closest
* vectors and returns those documents as search hits.
* <p>
* Elasticsearch uses the HNSW algorithm to support efficient kNN search. Like
* most kNN algorithms, HNSW is an approximate method that sacrifices result
* accuracy for improved search speed. This means the results returned are not
* always the true k closest neighbors.
* <p>
* The kNN search API supports restricting the search using a filter. The search
* will return the top k documents that also match the filter query.
* <p>
* A kNN search response has the exact same structure as a search API response.
* However, certain sections have a meaning specific to kNN search:
* <ul>
* <li>The document <code>_score</code> is determined by the similarity between
* the query and document vector.</li>
* <li>The <code>hits.total</code> object contains the total number of nearest
* neighbor candidates considered, which is
* <code>num_candidates * num_shards</code>. The
* <code>hits.total.relation</code> will always be <code>eq</code>, indicating
* an exact value.</li>
* </ul>
*
* @param fn
* a function that initializes a builder to create the
* {@link KnnSearchRequest}
* @see <a href=
* "https://www.elastic.co/guide/en/elasticsearch/reference/8.19/knn-search-api.html">Documentation
* on elastic.co</a>
*/

public final <TDocument> CompletableFuture<KnnSearchResponse<TDocument>> knnSearch(
Function<KnnSearchRequest.Builder, ObjectBuilder<KnnSearchRequest>> fn, Class<TDocument> tDocumentClass) {
return knnSearch(fn.apply(new KnnSearchRequest.Builder()).build(), tDocumentClass);
}

/**
* Overload of {@link #knnSearch(KnnSearchRequest, Class)}, where Class is
* defined as Void, meaning the documents will not be deserialized.
*/

public CompletableFuture<KnnSearchResponse<Void>> knnSearch(KnnSearchRequest request) {
@SuppressWarnings("unchecked")
JsonEndpoint<KnnSearchRequest, KnnSearchResponse<Void>, ErrorResponse> endpoint = (JsonEndpoint<KnnSearchRequest, KnnSearchResponse<Void>, ErrorResponse>) KnnSearchRequest._ENDPOINT;
return this.transport.performRequestAsync(request, endpoint, this.transportOptions);
}

/**
* Overload of {@link #knnSearch(Function, Class)}, where Class is defined as
* Void, meaning the documents will not be deserialized.
*/

public final CompletableFuture<KnnSearchResponse<Void>> knnSearch(
Function<KnnSearchRequest.Builder, ObjectBuilder<KnnSearchRequest>> fn) {
return knnSearch(fn.apply(new KnnSearchRequest.Builder()).build(), Void.class);
}

/**
* Run a knn search.
* <p>
* NOTE: The kNN search API has been replaced by the <code>knn</code> option in
* the search API.
* <p>
* Perform a k-nearest neighbor (kNN) search on a dense_vector field and return
* the matching documents. Given a query vector, the API finds the k closest
* vectors and returns those documents as search hits.
* <p>
* Elasticsearch uses the HNSW algorithm to support efficient kNN search. Like
* most kNN algorithms, HNSW is an approximate method that sacrifices result
* accuracy for improved search speed. This means the results returned are not
* always the true k closest neighbors.
* <p>
* The kNN search API supports restricting the search using a filter. The search
* will return the top k documents that also match the filter query.
* <p>
* A kNN search response has the exact same structure as a search API response.
* However, certain sections have a meaning specific to kNN search:
* <ul>
* <li>The document <code>_score</code> is determined by the similarity between
* the query and document vector.</li>
* <li>The <code>hits.total</code> object contains the total number of nearest
* neighbor candidates considered, which is
* <code>num_candidates * num_shards</code>. The
* <code>hits.total.relation</code> will always be <code>eq</code>, indicating
* an exact value.</li>
* </ul>
*
* @see <a href=
* "https://www.elastic.co/guide/en/elasticsearch/reference/8.19/knn-search-api.html">Documentation
* on elastic.co</a>
*/

public <TDocument> CompletableFuture<KnnSearchResponse<TDocument>> knnSearch(KnnSearchRequest request,
Type tDocumentType) {
@SuppressWarnings("unchecked")
JsonEndpoint<KnnSearchRequest, KnnSearchResponse<TDocument>, ErrorResponse> endpoint = (JsonEndpoint<KnnSearchRequest, KnnSearchResponse<TDocument>, ErrorResponse>) KnnSearchRequest._ENDPOINT;
endpoint = new EndpointWithResponseMapperAttr<>(endpoint,
"co.elastic.clients:Deserializer:_global.knn_search.Response.TDocument",
getDeserializer(tDocumentType));

return this.transport.performRequestAsync(request, endpoint, this.transportOptions);
}

/**
* Run a knn search.
* <p>
* NOTE: The kNN search API has been replaced by the <code>knn</code> option in
* the search API.
* <p>
* Perform a k-nearest neighbor (kNN) search on a dense_vector field and return
* the matching documents. Given a query vector, the API finds the k closest
* vectors and returns those documents as search hits.
* <p>
* Elasticsearch uses the HNSW algorithm to support efficient kNN search. Like
* most kNN algorithms, HNSW is an approximate method that sacrifices result
* accuracy for improved search speed. This means the results returned are not
* always the true k closest neighbors.
* <p>
* The kNN search API supports restricting the search using a filter. The search
* will return the top k documents that also match the filter query.
* <p>
* A kNN search response has the exact same structure as a search API response.
* However, certain sections have a meaning specific to kNN search:
* <ul>
* <li>The document <code>_score</code> is determined by the similarity between
* the query and document vector.</li>
* <li>The <code>hits.total</code> object contains the total number of nearest
* neighbor candidates considered, which is
* <code>num_candidates * num_shards</code>. The
* <code>hits.total.relation</code> will always be <code>eq</code>, indicating
* an exact value.</li>
* </ul>
*
* @param fn
* a function that initializes a builder to create the
* {@link KnnSearchRequest}
* @see <a href=
* "https://www.elastic.co/guide/en/elasticsearch/reference/8.19/knn-search-api.html">Documentation
* on elastic.co</a>
*/

public final <TDocument> CompletableFuture<KnnSearchResponse<TDocument>> knnSearch(
Function<KnnSearchRequest.Builder, ObjectBuilder<KnnSearchRequest>> fn, Type tDocumentType) {
return knnSearch(fn.apply(new KnnSearchRequest.Builder()).build(), tDocumentType);
}

// ----- Endpoint: mget

/**
Expand Down
Loading