Reputation: 171
I want to use the example on official documents combined with normal match and boolean queries. How to do that?
GET /_search
{
"query": {
"function_score": {
"field_value_factor": {
"field": "likes",
"factor": 1.2,
"modifier": "sqrt",
"missing": 1
}
}
}
}
Match query:
"query": {
"match" : {
"name" : "star wars"
}
}
Boolean query:
{
"query": {
"bool": {
"must": [
{
"match": {
"name": "Star Wars"
}
}
],
"should": [
{
"term": {
"name.keyword": {
"value": "Star Wars"
}
}
}
]
}
}
}
Upvotes: 2
Views: 4505
Reputation: 1286
Yes, this should be doable. If you read further down in the documentation that you linked to, there is an example:
GET /_search { "query": { "function_score": { "functions": [ { "gauss": { "price": { "origin": "0", "scale": "20" } } }, { "gauss": { "location": { "origin": "11, 12", "scale": "2km" } } } ], "query": { "match": { "properties": "balcony" } }, "score_mode": "multiply" } } }
Modifying that slightly for your use case should look something like this:
GET /_search
{
"query": {
"function_score": {
"functions": [
{
"field_value_factor": {
"field": "likes",
"factor": 1.2,
"modifier": "sqrt",
"missing": 1
}
}
],
"query": {
"match": {
"name": "Star Wars"
}
},
"score_mode": "multiply"
}
}
}
Disclaimer: I haven't tested this, just going off of the documentation.
Upvotes: 3