在使用es做全文检索时,可以使用match
来查询某个字段,如要查询标题中含有elasticsearch
相关的内容:
$client->search(
[
'index' => 'test',
'body' => [
'query' => [
'bool' => [
'must' => [
[
'match' => [
'title' => [
'query' => 'elasticsearch'
]
]
]
]
]
]
]
]
);
现在需要检索标题、副标题、内容都含有elasticsearch
相关的内容就可以使用multi_match
:
$client->search(
[
'index' => 'test',
'body' => [
'query' => [
'bool' => [
'must' => [
[
'multi_match' => [
'query' => 'elasticsearch',
'fields' => [
'title',
'subtitle',
'content'
]
]
]
]
]
]
]
]
);