这是我在 symfony2 中的查询。我想在这里添加“match_phrase”,但是在我添加的任何地方,我都会出错。
$params = [
'index' => 'articles_v2',
'type' => 'article',
'body' => [
"sort" => [
[ "date" =>
["order" => "desc"]
],
],
"from" => $fromId,
"size" => $newsPerPage,
"query" => [
"constant_score" => [
"filter" => [
"bool" => [
"must" => [
["terms" => [ "article.topics" => $topics ] ],
["match_phrase" => ["article.bodytext" => [$search_phrase] ]]
]
]
]
]
]
]
];
$response = $client->search($params);
当我尝试运行它时,出现错误: nested: QueryParsingException[[articles_v2] No filter registered for [match_phrase]]; }]","状态":400
那么这个 match_phrase 应该放在哪里呢?(我想得到类似 SQL LIKE '%xxxx%' 的结果)
我已经更改了查询。这次没有错误,但无论如何,没有过滤。
$params = [
'index' => 'articles_v2',
'type' => 'article',
'body' => [
"sort" => [
[ "date" =>
["order" => "desc"]
],
],
"from" => $fromId,
"size" => $newsPerPage,
"query" => [
"constant_score" => [
"filter" => [
"bool" => [
"must" => [
["terms" => [ "article.topics" => $topics ] ]
]
]
],
"query" => [
"multi_match" => [
"query" => $search_phrase,
"fields" => [ "title", "bodytext" ]
]
]
]
]
]
];
$response = $client->search($params);