我正在尝试在ElasticSearch查询中实现自定义评分。
在描述问题之前,我将描述我的用例。
我有一个实体Item
,其中包含几个字段:
types
(关键字):类型列表themes
(关键字):类型列表location
:商品的位置我的查询包含:
TYPE1
但没有TYPE2
和TYPE3
的项目TYPE4
的项目必须加2。具有THEME1
的项目必须加3。提供的多边形内的项目必须增加4。这是我尝试过的查询:
{
"from": 0,
"size": 10,
"query": {
"function_score": {
"boost": 1,
"boost_mode": "multiply",
"query": {
"bool": {
"filter": [
{
"term": {
"types": {
"value": "TYPE1"
}
}
},
{
"not": {
"filter": {
"term": {
"types": {
"value": [
"TYPE2",
"TYPE3"
]
}
}
}
}
}
]
}
},
"functions": [
{
"filter": {
"term": {
"themes": "THEME1"
}
},
"weight": 3
},
{
"filter": {
"term": {
"types": "TYPE4"
}
},
"weight": 2
},
{
"filter": {
"geo_polygon": {
"location": {
"points": [ ... ]
}
}
},
"weight": 4
}
]
}
},
"sort": [
"_score"
]
}
在此请求下,我收到此错误:
"type": "parsing_exception",
"reason": "no [query] registered for [not]",
因此,我认为问题出在not
块级别...
如果我删除了该块,则请求成功,但分数不是预期的分数(所有分数均为0
)。
我启用了explain
模式,可以看到以下内容:
"_explanation": {
"value": 0,
"description": "function score, product of:",
"details": [
{
"value": 0,
"description": "ConstantScore(types:TYPE1)^0.0",
"details": []
},
{
"value": 1,
"description": "min of:",
"details": [
{
"value": 1,
"description": "No function matched",
"details": []
},
{
"value": 3.4028235e+38,
"description": "maxBoost",
"details": []
}
]
}
]
所以我的问题是:
not
块?function_score
计算分数?感谢您的帮助, 蒂埃里