I use elastic 7.6 and Elastic4s client 7.6.0 I am working on a feature in that requires to change the ‘_score‘ of a subQuery in a bigger one: in all my big query would look something like this :
{"query": {
"function_score": {
"query": {
"bool": {
"must": [
{
"bool": {..}
},
{
"match": {}
....
{
"script_score": {
"query": {
"match_phrase": {
...
}
},
"script": {
"source": "..."
}
}
},
**more script queries** ...
}},
"max_boost": 3.4028235e+38,
"score_mode": "sum",
"boost_mode": "sum",
"functions": [ /some functions"]
}
}
so looking in elastic4s i found that there is a class that corresponds to what i want to achieve :
case class ScriptScoreQuery(script: String) extends Query
unfortunatly this means that it hasn't been implemented yet and i tried to work around it by using script_score feature confined with a filter like this :
ScriptScore( Script("_score * 2"),
weight = Some(defaultBoostValue),
Some(MatchPhrase(
field = "someField",
value = "keyword",
slop = Some(0),
boost = Some(defaultBoostValue)
))
this was translated using elastic4s like this :
{
"script_score": {
"script": {
"source": "_score * 2"
}
},
"weight": 1,
"filter": {
"match_phrase": {
"someField": {
"query": "keyword",
"slop": 0,
"boost": 1
}
}
}
},
vs what i need :
{
"script_score": {
"query": {
"match_phrase": {
"someFields": {
"query": "keyword",
"slop": 0,
"boost": 1
}
}
},
"script": {
"source": "_score) * 2"
}
}
},
After using the explain api it showed that the ‘_score‘ used is that of the global query, and it's not quite what i need
Is there a way to have an implementation that corresponds to the script score query introduced in elastic 7.0 ?