【发布时间】:2017-06-09 09:40:42
【问题描述】:
这是我在 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);
当我尝试运行此程序时,出现错误: 嵌套:QueryParsingException[[articles_v2] 没有为 [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);
【问题讨论】:
标签: symfony elasticsearch match-phrase