我想在结合正常匹配和布尔查询的正式文档上使用该示例。该怎么做?
GET /_search
{
"query": {
"function_score": {
"field_value_factor": {
"field": "likes",
"factor": 1.2,
"modifier": "sqrt",
"missing": 1
}
}
}
}
匹配查询:
"query": {
"match" : {
"name" : "star wars"
}
}
布尔查询:
{
"query": {
"bool": {
"must": [
{
"match": {
"name": "Star Wars"
}
}
],
"should": [
{
"term": {
"name.keyword": {
"value": "Star Wars"
}
}
}
]
}
}
}
答案 0 :(得分:1)
是的,这应该可行。如果您在documentation that you linked to中进一步阅读,将有一个示例:
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" } } }
针对您的用例进行略微修改应如下所示:
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"
}
}
}
免责声明:我还没有测试过,只是从文档中删除。