问题
我试图在脚本中使用布尔字段进行评分.看起来doc ['boolean_field'].值不能作为布尔值进行操作,但是_source.boolean_field.value可以(尽管这里的Scripting文档说的是"该字段的原生值.例如,如果它是短的类型,它会很短.").
我试过的
我有一个名为'is_new'的字段.这是映射:
PUT /test_index/test/_mapping
{
"test": {
"properties": {
"is_new": {
"type": "boolean"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我有一些文件:
PUT test_index/test/1
{
"is_new": true
}
PUT test_index/test/2
{
"is_new": false
}
Run Code Online (Sandbox Code Playgroud)
我想做一个function_score查询,如果是new则得分为1,如果不是则得0:
GET test_index/test/_search
{
"query": {
"function_score": {
"query": {
"match_all": {}
},
"functions": [
{
"script_score": {
"script": "<<my script>>",
"lang": "groovy"
}
}
],
"boost_mode": "replace"
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我使用_source.is_new.value字段时脚本工作,但如果我使用doc ['is_new'].value则不行.
这有效:
"if ( _source.is_new) {1} else {0}"
Run Code Online (Sandbox Code Playgroud)
这些不起作用:
"if ( doc['is_new'].value) {1} …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试在NEST中实现“ function_score”查询,仅在过滤器匹配时才应用这些函数。
看起来FunctionScoreFunctionsDescriptor尚不支持添加过滤器。是否会在不久的将来添加此功能?
这是我想要实现的超基本示例:
"function_score": {
"query": {...}, // base ES query
"functions": [
{
"filter": {...},
"script_score": {"script": "25"}
},
{
"filter": {...},
"script_score": {"script": "15"}
}
],
"score_mode": "first", // take the first script_score where the filter matches
"boost_mode": "sum" // and add this to the base ES query score
}
Run Code Online (Sandbox Code Playgroud)
我目前正在使用Elasticsearch v1.1.0和NEST v1.0.0-beta1预发行版。
谢谢!