我使用的与Boost Fields
的Elastic Search 1.7
。它工作正常,但在某些情况下,我没有得到预期的结果。
查询:弹性搜索中带有提升字段的查询字符串
query
{
"from": 0,
"size": 10,
"explain": true,
"query": {
"function_score": {
"query": {
"query_string": {
"query": "account and data",
"fields": [
"title^5"
"authors^4",
"year^5",
"topic^6"
],
"default_operator": "and",
"analyze_wildcard": true
}
},
"score_mode": "sum",
"boost_mode": "sum",
"max_boost": 100
}
}
}
示例数据:
{
"took": 50,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 12.833213,
"hits": [
{
"_id": "19850",
"_score": 12.833213,
"_source": {
"ID": "19850",
"Year": "2010",
"Title": "account and data :..."
}
},
{
"_id": "16896",
"_score": 11.867042,
"_source": {
"ID": "16896",
"Year": "2014",
"Title": "effectivness of data..."
}
},
{
"_id": "59862",
"_score": 9.706333,
"_source": {
"ID": "59862",
"Year": "2007",
"Title": "best system to..."
}
},
{
"_id": "18501",
"_score": 9.685843,
"_source": {
"ID": "18501",
"Year": "2010",
"Title": "management of..."
}
}
]
}
我通过使用查询得到上述样品的数据,这是按照期望。但是现在,如果我将的year
增加到100,那么我期望第四名成绩在第三名,第三名成绩在第四名。我尝试了很多东西,但我不知道我做错了什么。
我是否需要添加所有字段,无论我想要考虑订购? –
您需要在订购时添加您想要考虑的字段。但是'field_value_factor'' field'属性只需要一个字段。如果你想使它成为两个字段的组合并添加自定义逻辑,你应该使用'script_score'来代替这里提到的https://www.elastic.co/guide/en/elasticsearch/guide/current/function-score -query.html –
如果这解决了您的问题,请记住将答案标记为已接受。 –