我想在弹性搜索中搜索我的自定义评分脚本中是否存在字段.
此搜索有效:
{
"query": {
"custom_score": {
"script": "((doc['region'].value == '1') ? 1 : 0)",
"query": {
"constant_score": {
"filter": {
"and": [
{
"term": {
"id": "100"
}
}
]
}
}
}
}
},
"size": 1
}
Run Code Online (Sandbox Code Playgroud)
如果区域字段值为1,它将结果评分为1.
但是,此查询将不起作用:如果文档中不存在区域字段,则不会将文档评分为1:
{
"query": {
"custom_score": {
"script": "((doc['region'].value == null) ? 1 : 0)",
"query": {
"constant_score": {
"filter": {
"and": [
{
"term": {
"id": "100"
}
}
]
}
}
}
}
},
"size": 1
}
Run Code Online (Sandbox Code Playgroud)
如何检查脚本中的缺失值?
| 归档时间: |
|
| 查看次数: |
3722 次 |
| 最近记录: |