elasticsearch - 使用function_score时如何向弹性查询添加过滤器?
问题描述
这是我当前的弹性查询:
{
"from": 0,
"size": 10,
"query": {
"function_score": {
"query": {
"bool": {
"must": [{
"multi_match": {
"query": "ocean",
"fields": [],
"fuzziness": "AUTO"
}}],
"must_not": [{
"exists": {
"field": "parentId"
}
}]
}
},
"functions" : [
{
"gauss": {
"createTime": {
"origin": "2020-07-09T23:50:00",
"scale": "365d",
"decay": 0.3
}
}
}
]
}
}
}
如何正确添加过滤器?我想也许我正在使用的事实function_score
使这有所不同?我想添加一个硬过滤器,例如,只向我显示带有uploadUser: 'Mr. Bean'
... 的结果,但仍然为通过此过滤器的结果保留评分。
我尝试filter
在各个地方使用,也使用,must
但我没有得到任何结果或所有结果。
我正在使用 Elastic Search 7。感谢您的帮助
解决方案
您可以尝试以下搜索查询:
参考这个 ES 官方文档了解更多关于函数分数查询的信息
{
"from": 0,
"size": 10,
"query": {
"function_score": {
"query": {
"bool": {
"filter": {
"term": {
"uploadUser": "Mr. Bean"
}
},
"must": [
{
"multi_match": {
"query": "ocean",
"fields": [
],
"fuzziness": "AUTO"
}
}
],
"must_not": [
{
"exists": {
"field": "parentId"
}
}
]
}
},
"functions": [
{
"gauss": {
"createTime": {
"origin": "2020-07-09T23:50:00",
"scale": "365d",
"decay": 0.3
}
}
}
]
}
}
}
推荐阅读
- python - 熊猫在组内排序然后聚合
- python-3.x - xarray中的乘法
- kotlin - 如何在 Kotlin 中一次运行两个 for 循环?
- .net - OData .Net Core 实现添加过滤器附加括号
- python - 如何从 API 响应中提取值
- c++ - std::chrono::system_clock 和 C 时间
- mongodb - mongodb备份和还原中的大小不匹配
- javascript - React Native,将 JSON 数据显示为标题和列表(类别和子类别
- c# - 将引用添加到项目时的事件
- javascript - 如果其他正确,我如何使用“lengthMenu:[10,25,50]”?