当我尝试在查询中匹配一个字段时,一切都可以正常使用highlighting in elasticsearch。
当我尝试使用时:
$params = [
'index' => 'my_index',
'type' => 'articles',
'body' => [
'from' => '0',
'size' => '10',
'query' => [
'bool' => [
'must' => [
'match' => [ 'content' => 'what I want to search' ]
]
]
],
'highlight' => [
'pre_tags' => ['<mark>'],
'post_tags' => ['</mark>'],
'fields' => [
'content' => [ 'fragment_size' => 150, 'number_of_fragments' => 3 ]
]
],
]
];
一切正常,但当我尝试捕捉多个字段时,我的搜索工作正常,但突出显示消失。
'match' => [ 'content' => 'what I want to search' ],
'match' => [ 'type' => 1 ]
当我想在两个不同的字段中应用两个不同的查询时,您知道如何实现功能突出显示吗?
答案 0 :(得分:0)
试试这个:
$params = [
'index' => 'my_index',
'type' => 'articles',
'body' => [
'from' => '0',
'size' => '10',
'query' => [
'bool' => [
'must' => [
'match' => [ 'content' => 'what I want to search' ]
]
],
'filter' => ['type' => 1]
]
] ],
'highlight' => [
'pre_tags' => ['<mark>'],
'post_tags' => ['</mark>'],
'fields' => [
'content' => [ 'fragment_size' => 150, 'number_of_fragments' => 3 ]
]
],
]