【发布时间】:2022-10-25 12:51:52
【问题描述】:
我在 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]]
],
]
],
任何帮助深表感谢
【问题讨论】:
标签: php elasticsearch