queryNode
Allows to replace a specific query expression node using a handle of the node.
Samples
import dev.evo.elasticmagic.SearchQuery
import dev.evo.elasticmagic.aggs.HistogramAgg
import dev.evo.elasticmagic.aggs.TermsAgg
import dev.evo.elasticmagic.doc.Document
import dev.evo.elasticmagic.query.Bool
import dev.evo.elasticmagic.query.FunctionScore
import dev.evo.elasticmagic.query.MatchPhrase
import dev.evo.elasticmagic.query.MultiMatch
import dev.evo.elasticmagic.query.NodeHandle
import dev.evo.elasticmagic.query.QueryExpressionNode
import dev.evo.elasticmagic.query.QueryRescore
import dev.evo.elasticmagic.query.match
import kotlin.random.Random
fun main() {
//sampleStart
val BOOST_HANDLE = NodeHandle<FunctionScore>()
searchQuery.query(
QueryExpressionNode(
BOOST_HANDLE,
FunctionScore(
query = MultiMatch("system", listOf(UserDoc.name, UserDoc.about)),
functions = listOf(
FunctionScore.FieldValueFactor(
UserDoc.rank,
missing = 1.0F,
factor = 2.0F,
modifier = FunctionScore.FieldValueFactor.Modifier.LN1P
)
),
scoreMode = FunctionScore.ScoreMode.SUM,
)
)
)
val boostActive = Random.nextBoolean()
if (boostActive) {
// Move active users the top
searchQuery.queryNode(BOOST_HANDLE) { node ->
node.copy(
functions = node.functions + listOf(
FunctionScore.Weight(
1000.0F,
filter = UserDoc.isActive.eq(true)
)
)
)
}
}
//sampleEnd
}
Parameters
handle
a handle bound to the specific query expression node.
block
a function that returns new query expression node.
Throws
if a node specified by the handle is missing.