我刚刚在我的 Windows 机器上下载并安装了最新版本的 Elasticsearch。我做了第一次搜索查询,一切似乎都正常。然而。当我尝试突出显示搜索结果时,我失败了。所以,这就是我的查询的样子:
$params = [
'index' => 'test_index',
'type' => 'test_index_type',
'body' => [
'query' => [
'bool' => [
'should' => [ 'match' => [ 'field1' => '23' ] ]
]
],
'highlight' => [
'pre_tags' => "<em>",
'post_tags' => "</em>",
'fields' => (object)Array('field1' => new stdClass),
'require_field_match' => false
]
]
]
$res = $client->search($params);
总的来说,查询本身工作得很好——结果被过滤了。在我看到的控制台中,所有文档确实在其field1
字段中包含“23”值。但是,这些标签 -<em></em>
根本不会添加到结果中。我看到的只是field1
像“ some text 23
”,“ 23 another text
”这样的原始值。这不是我期望看到的——“ some text <em>23</em>
”、“ <em>23</em> another text
”。那么,这有什么问题,我该如何解决?