我在PHP中有一个查询,它已经在工作了,现在我想用function_score扩展它。目标是我可以基于时间戳来提升更新的内容。
我发现了这篇文章https://discuss.elastic.co/t/how-to-prioritize-more-recent-content/134100,也在阅读这篇文档https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html。
我想这是一种错位的新的一部分,但我不知道把它放在哪里。我很新的ElasticSearch。
错误
"type":"parsing_exception",
"reason":"[function_score] malformed query, expected [END_OBJECT] but found [FIELD_NAME]"
新零件
'function_score' => [
'functions' => [
[
'filter'=> [
'range' => [
'tstamp' => [
'gte' => 'now-1y',
'lte' => 'now'
]
]
],
'weight' => 5
],
[
'filter' => [
'range' => [
'tstamp' => [
'gte' => 'now-3yr',
'lte' => 'now-1yr'
]
]
],
'weight' => 2
]
],
'boost_mode' => 'multiply'
],
完整查询
'query' => [
'function_score' => [
'functions' => [
[
'filter'=> [
'range' => [
'tstamp' => [
'gte' => 'now-1y',
'lte' => 'now'
]
]
],
'weight' => 5
],
[
'filter' => [
'range' => [
'tstamp' => [
'gte' => 'now-3yr',
'lte' => 'now-1yr'
]
]
],
'weight' => 2
]
],
'boost_mode' => 'multiply'
],
'bool' => [
'filter' => [
['range' => [
'starttime' => ['lte' => $now],
]]
],
'must' => [
["multi_match" => [
'fuzziness' => 'auto',
'query' => $_REQUEST['kw'],
'fields' => [
'content^2',
'teaser^2',
'bodytext^2',
'title^5',
'header^3'
],
]],
['bool' => [
'should' => [
['match' => ['sys_language_uid' => $sysLanguageUid]],
['match' => ['sys_language_uid' => -1]],
],
'minimum_should_match' => 1,
]],
],
'must_not' => [
['match' => ['hidden' => 1]],
['match' => ['deleted' => 1]],
['match' => ['no_search' => 1]]
],
]
],
任何帮助都是非常感谢的
1条答案
按热度按时间juzqafwq1#
我找到了解决方案。下面是有效的完整查询。我希望它能帮助其他人:
“查询”部分属于“函数_分数”: