Elasticsearch 不合并亮点
Elasticsearch not merging highlights
我有一个使用 ngram 分词器编制索引的 elasticsearch 字段。没想到elasticsearch并没有合并相邻的highlight。例如,对于搜索词854511
,我得到以下亮点
DA V50 v335 auf v331 J06A <mark>85</mark><mark>45</mark><mark>11</mark>
虽然我希望如此
DA V50 v335 auf v331 J06A <mark>854511</mark>
这是我的分析器:
ADDITIONAL_ANALYZERS = {
analyzer: {
ngram_analyzer: {
tokenizer: :ngram_tokenizer,
filter: 'lowercase'
}},
tokenizer: {
ngram_tokenizer: {type: :nGram,
min_gram: 2,
max_gram: 20,
token_chars: [ 'letter', 'digit', 'symbol', 'punctuation' ]
}}
}
settings analysis: ADDITIONAL_ANALYZERS do
mappings do
indexes :name, type: 'multi_field' do
indexes :name, type: :string, analyzer: :ngram_analyzer, term_vector: :with_positions_offsets
indexes :not_analyzed, type: :string, index: :not_analyzed
end
indexes :mdc, type: :string, index: :not_analyzed
indexes :description, type: :string, analyzer: :html_ngram_analyzer, term_vector: :with_positions_offsets
indexes :created_at, type: :date
end
end
尝试使用 plain
荧光笔。
如果您尝试以下查询:
{
"query": {
"match": {
"name": "854511"
}
},
"highlight": {
"fields": {
"name": {
"pre_tags": [
"<mark>"
],
"post_tags": [
"</mark>"
],
"fragment_size": 150,
"number_of_fragments": 1,
"type": "plain"
}
}
}
}
您得到了想要的结果:
"hits": [
{
"_index": "test",
"_type": "test",
"_id": "1",
"_score": 0.1856931,
"_source": {
"name": "DA V50 v335 auf v331 J06A 854511"
},
"highlight": {
"name": [
"DA V50 v335 auf v331 J06A <mark>854511</mark>"
]
}
}
]
我有一个使用 ngram 分词器编制索引的 elasticsearch 字段。没想到elasticsearch并没有合并相邻的highlight。例如,对于搜索词854511
,我得到以下亮点
DA V50 v335 auf v331 J06A <mark>85</mark><mark>45</mark><mark>11</mark>
虽然我希望如此
DA V50 v335 auf v331 J06A <mark>854511</mark>
这是我的分析器:
ADDITIONAL_ANALYZERS = {
analyzer: {
ngram_analyzer: {
tokenizer: :ngram_tokenizer,
filter: 'lowercase'
}},
tokenizer: {
ngram_tokenizer: {type: :nGram,
min_gram: 2,
max_gram: 20,
token_chars: [ 'letter', 'digit', 'symbol', 'punctuation' ]
}}
}
settings analysis: ADDITIONAL_ANALYZERS do
mappings do
indexes :name, type: 'multi_field' do
indexes :name, type: :string, analyzer: :ngram_analyzer, term_vector: :with_positions_offsets
indexes :not_analyzed, type: :string, index: :not_analyzed
end
indexes :mdc, type: :string, index: :not_analyzed
indexes :description, type: :string, analyzer: :html_ngram_analyzer, term_vector: :with_positions_offsets
indexes :created_at, type: :date
end
end
尝试使用 plain
荧光笔。
如果您尝试以下查询:
{
"query": {
"match": {
"name": "854511"
}
},
"highlight": {
"fields": {
"name": {
"pre_tags": [
"<mark>"
],
"post_tags": [
"</mark>"
],
"fragment_size": 150,
"number_of_fragments": 1,
"type": "plain"
}
}
}
}
您得到了想要的结果:
"hits": [
{
"_index": "test",
"_type": "test",
"_id": "1",
"_score": 0.1856931,
"_source": {
"name": "DA V50 v335 auf v331 J06A 854511"
},
"highlight": {
"name": [
"DA V50 v335 auf v331 J06A <mark>854511</mark>"
]
}
}
]