我有一个wordpress网站,它使用Jetpack / Elasticsearch(PHP而不是JSON)。我正在尝试编写查询以按“ post_type”对结果进行优先级排序。我有4种职位类型。我想要他们按此顺序:
页面,帖子,新闻,新闻。
我想先按页面进行优先排序,然后按标题对match_phrase进行排序,
然后按发布确定优先级,并按标题
匹配_phrase
然后按新闻确定优先级,并按标题
匹配_phrase
然后按按进行优先级排序,并按标题对match_phrase进行排序。
然后按页面进行优先级排序,并按内容对match_phrase进行排序,
然后按 post 进行优先级排序,然后按内容进行match_phrase排序,
然后按新闻进行优先级排序,并按内容进行match_phrase排序,
然后按按进行优先级排序,然后按内容进行match_phrase排序。
这是我尝试过的:
$es_query_args['query']['function_score']['query']['bool'] = [
"must" => [
"match" => [
"title" => $query,
"fuzziness" => "auto"
]
],
"should" => [
"match" => [
"post_type" => [
// matching phrase in title
[ "page^28" => ["match_phrase" => "title", "operator" => "and" ]],
[ "post^27" => ["match_phrase" => "title", "operator" => "and" ]],
[ "news^26" => ["match_phrase" => "title", "operator" => "and" ]],
[ "press^25" => ["match_phrase" => "title", "operator" => "and" ]],
// matching phrase in content
[ "page^24" => ["match_phrase" => "meta.search_content.value", "operator" => "and" ]],
[ "post^23" => ["match_phrase" => "meta.search_content.value", "operator" => "and" ]],
[ "news^22" => ["match_phrase" => "meta.search_content.value", "operator" => "and" ]],
[ "press^21" => ["match_phrase" => "meta.search_content.value", "operator" => "and" ]],
]
]
]
];
这行不通。
我用胡萝卜符号(^)对查询施加权重。我也不知道这是正确的。
最终目标是当我搜索“ The Perfect Salmon Recipe”一词时,我希望它先按标题按页面优先,然后按标题按职位等等。当我说“优先”时,我的意思是我希望这些结果在搜索结果中得到增强。
我需要编写一个嵌套查询吗?如果是这样,我该怎么办?