Class KnnSearchRequest
- All Implemented Interfaces:
JsonpSerializable
NOTE: The kNN search API has been replaced by the knn
option in
the search API.
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.
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.
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.
A kNN search response has the exact same structure as a search API response. However, certain sections have a meaning specific to kNN search:
- The document
_score
is determined by the similarity between the query and document vector. - The
hits.total
object contains the total number of nearest neighbor candidates considered, which isnum_candidates * num_shards
. Thehits.total.relation
will always beeq
, indicating an exact value.
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class co.elastic.clients.elasticsearch._types.RequestBase
RequestBase.AbstractBuilder<BuilderT extends RequestBase.AbstractBuilder<BuilderT>>
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final JsonpDeserializer<KnnSearchRequest>
Deprecated.Json deserializer forKnnSearchRequest
static final SimpleEndpoint<KnnSearchRequest,
?> Deprecated.Endpoint "knn_search
". -
Method Summary
Modifier and TypeMethodDescriptionstatic <TDocument>
Endpoint<KnnSearchRequest,KnnSearchResponse<TDocument>, ErrorResponse> createKnnSearchEndpoint
(JsonpDeserializer<TDocument> tDocumentDeserializer) Deprecated.Create an "knn_search
" endpoint.final List<FieldAndFormat>
Deprecated.The request returns doc values for field names matching these patterns in thehits.fields
property of the response.fields()
Deprecated.The request returns values for field names matching these patterns in thehits.fields
property of the response.filter()
Deprecated.A query to filter the documents that can match.index()
Deprecated.Required - A comma-separated list of index names to search; use_all
or to perform the operation on all indices.final KnnSearchQuery
knn()
Deprecated.Required - The kNN query to run.static KnnSearchRequest
Deprecated.final String
routing()
Deprecated.A comma-separated list of specific routing values.void
serialize
(jakarta.json.stream.JsonGenerator generator, JsonpMapper mapper) Deprecated.Serialize this object to JSON.protected void
serializeInternal
(jakarta.json.stream.JsonGenerator generator, JsonpMapper mapper) Deprecated.protected static void
Deprecated.final SourceConfig
source()
Deprecated.Indicates which source fields are returned for matching documents.Deprecated.A list of stored fields to return as part of a hit.Methods inherited from class co.elastic.clients.elasticsearch._types.RequestBase
toString
-
Field Details
-
_DESERIALIZER
Deprecated.Json deserializer forKnnSearchRequest
-
_ENDPOINT
Deprecated.Endpoint "knn_search
".
-
-
Method Details
-
of
public static KnnSearchRequest of(Function<KnnSearchRequest.Builder, ObjectBuilder<KnnSearchRequest>> fn) Deprecated. -
source
Deprecated.Indicates which source fields are returned for matching documents. These fields are returned in thehits._source
property of the search response.API name:
_source
-
docvalueFields
Deprecated.The request returns doc values for field names matching these patterns in thehits.fields
property of the response. It accepts wildcard (*
) patterns.API name:
docvalue_fields
-
fields
Deprecated.The request returns values for field names matching these patterns in thehits.fields
property of the response. It accepts wildcard (*
) patterns.API name:
fields
-
filter
Deprecated.A query to filter the documents that can match. The kNN search will return the topk
documents that also match this filter. The value can be a single query or a list of queries. Iffilter
isn't provided, all documents are allowed to match.API name:
filter
-
index
Deprecated.Required - A comma-separated list of index names to search; use_all
or to perform the operation on all indices.API name:
index
-
knn
Deprecated.Required - The kNN query to run.API name:
knn
-
routing
Deprecated.A comma-separated list of specific routing values.API name:
routing
-
storedFields
Deprecated.A list of stored fields to return as part of a hit. If no fields are specified, no stored fields are included in the response. If this field is specified, the_source
parameter defaults tofalse
. You can pass_source: true
to return both source fields and stored fields in the search response.API name:
stored_fields
-
serialize
Deprecated.Serialize this object to JSON.- Specified by:
serialize
in interfaceJsonpSerializable
-
serializeInternal
Deprecated. -
setupKnnSearchRequestDeserializer
protected static void setupKnnSearchRequestDeserializer(ObjectDeserializer<KnnSearchRequest.Builder> op) Deprecated. -
createKnnSearchEndpoint
public static <TDocument> Endpoint<KnnSearchRequest,KnnSearchResponse<TDocument>, createKnnSearchEndpointErrorResponse> (JsonpDeserializer<TDocument> tDocumentDeserializer) Deprecated.Create an "knn_search
" endpoint.
-
knn
option in the search API.