Class Knn
java.lang.Object
org.elasticsearch.xpack.esql.core.tree.Node<Expression>
org.elasticsearch.xpack.esql.core.expression.Expression
org.elasticsearch.xpack.esql.core.expression.function.Function
org.elasticsearch.xpack.esql.expression.function.fulltext.FullTextFunction
org.elasticsearch.xpack.esql.expression.function.fulltext.SingleFieldFullTextFunction
org.elasticsearch.xpack.esql.expression.function.vector.Knn
- All Implemented Interfaces:
NamedWriteable,Writeable,PostAnalysisPlanVerificationAware,PostOptimizationPlanVerificationAware,PostOptimizationVerificationAware,RewriteableAware,TranslationAware,Resolvable,EvaluatorMapper,OptionalArgument,VectorFunction,ExpressionScoreMapper
public class Knn
extends SingleFieldFullTextFunction
implements OptionalArgument, VectorFunction, PostOptimizationVerificationAware
-
Nested Class Summary
Nested classes/interfaces inherited from class org.elasticsearch.xpack.esql.core.expression.Expression
Expression.TypeResolutionNested classes/interfaces inherited from interface org.elasticsearch.xpack.esql.evaluator.mapper.EvaluatorMapper
EvaluatorMapper.ToEvaluatorNested classes/interfaces inherited from interface org.elasticsearch.xpack.esql.score.ExpressionScoreMapper
ExpressionScoreMapper.ToScorerNested classes/interfaces inherited from interface org.elasticsearch.xpack.esql.capabilities.PostOptimizationVerificationAware
PostOptimizationVerificationAware.CoordinatorOnlyNested classes/interfaces inherited from interface org.elasticsearch.xpack.esql.capabilities.TranslationAware
TranslationAware.FinishedTranslatable, TranslationAware.SingleValueTranslationAware, TranslationAware.TranslatableNested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V> -
Field Summary
FieldsFields inherited from class org.elasticsearch.xpack.esql.expression.function.fulltext.SingleFieldFullTextFunction
fieldFields inherited from class org.elasticsearch.xpack.esql.core.tree.Node
TO_STRING_MAX_WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionKnn(Source source, Expression field, Expression query, Expression options) Knn(Source source, Expression field, Expression query, Expression options, Integer implicitK, QueryBuilder queryBuilder, List<Expression> filterExpressions) -
Method Summary
Modifier and TypeMethodDescriptionbooleanprotected QueryBuilderReturns the query builder to be used when the function cannot be pushed down to Lucene, but uses aLuceneQueryEvaluatorinsteadReturns the allowed options map for this function.Returns the set of allowed data types for the field parameter.Returns the set of allowed data types for the query parameter.inthashCode()protected NodeInfo<? extends Expression> info()voidpostOptimizationVerification(Failures failures) Validates the implementing expression - discovered failures are reported to the givenFailuresclass.Converts the query expression to an Object suitable for the Lucene query.replaceChildren(List<Expression> newChildren) replaceQueryBuilder(QueryBuilder queryBuilder) Replaces the current query builder with a rewritten iteration.translatable(LucenePushdownPredicates pushdownPredicates) Can this instance be translated or not? Usually checks whether the expression arguments are actual fields that exist in Lucene.protected Querytranslate(LucenePushdownPredicates pushdownPredicates, TranslatorHandler handler) withFilters(List<Expression> filterExpressions) voidwriteTo(StreamOutput out) Methods inherited from class org.elasticsearch.xpack.esql.expression.function.fulltext.SingleFieldFullTextFunction
expectedFieldTypesString, expectedQueryTypesString, field, fieldAsFieldAttribute, fold, foldable, nullable, options, postAnalysisPlanVerification, postOptimizationPlanVerification, resolveField, resolveOptions, resolveParams, resolveQueryMethods inherited from class org.elasticsearch.xpack.esql.expression.function.fulltext.FullTextFunction
asQuery, dataType, fieldAsFieldAttribute, fieldVerifier, functionType, getNameFromFieldAttribute, query, queryBuilder, resolveQuery, resolveType, toEvaluator, toScorerMethods inherited from class org.elasticsearch.xpack.esql.core.expression.function.Function
arguments, functionName, nodeStringMethods inherited from class org.elasticsearch.xpack.esql.core.expression.Expression
canonical, canonicalize, childrenResolved, propertiesToString, references, resolved, semanticEquals, semanticHash, toString, typeResolvedMethods inherited from class org.elasticsearch.xpack.esql.core.tree.Node
anyMatch, children, collect, collect, collect, collectFirstChildren, collectLeaves, doCollectFirst, forEachDown, forEachDown, forEachDownMayReturnEarly, forEachProperty, forEachPropertyDown, forEachPropertyOnly, forEachPropertyUp, forEachUp, forEachUp, nodeName, nodeProperties, replaceChildrenSameSize, source, sourceLocation, sourceText, transformChildren, transformDown, transformDown, transformDown, transformNodeProps, transformPropertiesDown, transformPropertiesOnly, transformPropertiesUp, transformUp, transformUp, transformUpMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.elasticsearch.xpack.esql.evaluator.mapper.EvaluatorMapper
foldMethods inherited from interface org.elasticsearch.xpack.esql.capabilities.TranslationAware
asLuceneQuery
-
Field Details
-
ENTRY
-
MIN_CANDIDATES_OPTION
- See Also:
-
ALLOWED_OPTIONS
-
-
Constructor Details
-
Knn
-
Knn
public Knn(Source source, Expression field, Expression query, Expression options, Integer implicitK, QueryBuilder queryBuilder, List<Expression> filterExpressions)
-
-
Method Details
-
implicitK
-
filterExpressions
-
withImplicitK
-
queryAsObject
Description copied from class:SingleFieldFullTextFunctionConverts the query expression to an Object suitable for the Lucene query. Handles common conversions for BytesRef, UNSIGNED_LONG, DATETIME, and DATE_NANOS.- Overrides:
queryAsObjectin classSingleFieldFullTextFunction
-
replaceQueryBuilder
Description copied from interface:RewriteableAwareReplaces the current query builder with a rewritten iteration. This happens multiple times through the rewrite phase until the final iteration of the query builder is stored.- Specified by:
replaceQueryBuilderin interfaceRewriteableAware- Parameters:
queryBuilder- QueryBuilder- Returns:
- Expression defining the active QueryBuilder
-
translatable
Description copied from interface:TranslationAwareCan this instance be translated or not? Usually checks whether the expression arguments are actual fields that exist in Lucene. SeeTranslationAware.Translatablefor precisely what can be signaled from this method.- Specified by:
translatablein interfaceTranslationAware- Overrides:
translatablein classFullTextFunction
-
translate
- Specified by:
translatein classFullTextFunction
-
withFilters
-
evaluatorQueryBuilder
Description copied from class:FullTextFunctionReturns the query builder to be used when the function cannot be pushed down to Lucene, but uses aLuceneQueryEvaluatorinstead- Overrides:
evaluatorQueryBuilderin classFullTextFunction- Returns:
- the query builder to be used in the
LuceneQueryEvaluator
-
postOptimizationVerification
Description copied from interface:PostOptimizationVerificationAwareValidates the implementing expression - discovered failures are reported to the givenFailuresclass.Example: the
Bucketfunction, which produces buckets over a numerical or date field, based on a number of literal arguments needs to check if its arguments are all indeed literals. This is how this verification is performed:@Override public void postOptimizationVerification(Failures failures) { String operation = sourceText(); failures.add(isFoldable(buckets, operation, SECOND)) .add(from != null ? isFoldable(from, operation, THIRD) : null) .add(to != null ? isFoldable(to, operation, FOURTH) : null); }- Specified by:
postOptimizationVerificationin interfacePostOptimizationVerificationAware- Overrides:
postOptimizationVerificationin classFullTextFunction
-
replaceChildren
- Specified by:
replaceChildrenin classNode<Expression>
-
info
- Specified by:
infoin classNode<Expression>
-
getWriteableName
- Specified by:
getWriteableNamein interfaceNamedWriteable
-
writeTo
- Specified by:
writeToin interfaceWriteable- Throws:
IOException
-
getFieldDataTypes
Description copied from class:SingleFieldFullTextFunctionReturns the set of allowed data types for the field parameter. Each subclass defines which field types it supports.- Specified by:
getFieldDataTypesin classSingleFieldFullTextFunction
-
getQueryDataTypes
Description copied from class:SingleFieldFullTextFunctionReturns the set of allowed data types for the query parameter. Each subclass defines which query types it supports.- Specified by:
getQueryDataTypesin classSingleFieldFullTextFunction
-
getAllowedOptions
Description copied from class:SingleFieldFullTextFunctionReturns the allowed options map for this function. Keys are option names, values are the expected data types.- Specified by:
getAllowedOptionsin classSingleFieldFullTextFunction
-
equals
- Overrides:
equalsin classSingleFieldFullTextFunction
-
hashCode
public int hashCode()- Overrides:
hashCodein classSingleFieldFullTextFunction
-