有一个字段的匹配不做过滤来用,条件满足就返回1不满足就返回2,其他逻辑在代码中处理,所以匹配怎么来返回呢?
我现在用的两个方法都是很傻的,但是还没找到更好的办法
1.script_field返回一个自己建的字段
{
"query": {
"match_all":{}
},
"script_fields": {
"test1": {
"script": {
"lang": "painless",
"source": "doc['user_list.keyword'].value!=null && doc['user_list.keyword'].value.contains('aaa')"
}
}
}
}
2.使用高亮,当然这种方法有人会问为什么不直接设置分数?我分数还有其他作用,不能被影响
{
"query": {
{"function_score": {
"score_mode": "max",
"boost_mode": "replace",
"functions": {
"filter":{
"match": {
"user_list": "aa"
}
},
"weight":0
}
}}
}
},
"highlight": {
"fields": {
"user_list": { "fragment_size": 1}
}
}
}