【发布时间】:2018-08-12 06:46:35
【问题描述】:
我在 ES 6.1.1 中使用 nGram 标记器并得到一些奇怪的亮点:
- 多个相邻字符 ngram 高亮不会合并为一个
-
tra在文档 9 中被错误地突出显示
查询 auftrag 与预期的文档 7 和 9 匹配,但在文档 9 中 betrag 未正确突出显示。这是荧光笔的问题 - 如果问题出在查询 doc 8 也会被返回。
示例代码
#!/usr/bin/env bash
# Example based on
# https://www.elastic.co/guide/en/elasticsearch/guide/current/ngrams-compound-words.html
# with suggestions from from
# https://github.com/elastic/elasticsearch/issues/21000
如果存在则删除索引
curl -sS -XDELETE 'localhost:9200/my_index'
printf '\n-------------\n'
创建新索引
curl -sS -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
{
"settings": {
"analysis": {
"analyzer": {
"trigrams": {
"tokenizer": "my_ngram_tokenizer",
"filter": ["lowercase"]
}
},
"tokenizer": {
"my_ngram_tokenizer": {
"type": "nGram",
"min_gram": "3",
"max_gram": "3",
"token_chars": [
"letter",
"digit",
"symbol",
"punctuation"
]
}
}
}
},
"mappings": {
"my_type": {
"properties": {
"text": {
"type": "text",
"analyzer": "trigrams",
"term_vector": "with_positions_offsets"
}
}
}
}
}
'
printf '\n-------------\n'
填充索引
curl -sS -XPOST 'localhost:9200/my_index/my_type/_bulk?pretty' -H 'Content-Type: application/json' -d'
{ "index": { "_id": 7 }}
{ "text": "auftragen" }
{ "index": { "_id": 8 }}
{ "text": "betrag" }
{ "index": { "_id": 9 }}
{ "text": "betrag auftragen" }
'
printf '\n-------------\n'
sleep 1 # Give ES time to index
查询
curl -sS -XGET 'localhost:9200/my_index/my_type/_search?pretty' -H 'Content-Type: application/json' -d'
{
"query": {
"match": {
"text": {
"query": "auftrag",
"minimum_should_match": "100%"
}
}
},
"highlight": {
"fields": {
"text": {
"fragment_size": 120,
"type": "fvh"
}
}
}
}
'
我得到的点击是(缩写):
"hits" : [
{
"_id" : "9",
"_source" : {
"text" : "betrag auftragen"
},
"highlight" : {
"text" : [
"be<em>tra</em>g <em>auf</em><em>tra</em>gen"
]
}
},
{
"_id" : "7",
"_source" : {
"text" : "auftragen"
},
"highlight" : {
"text" : [
"<em>auf</em><em>tra</em>gen"
]
}
}
]
我尝试了各种解决方法,例如使用统一/fvh 荧光笔并设置所有似乎相关的选项,但没有运气。非常感谢任何提示。
【问题讨论】:
-
嗯...我正在使用您的上述设置对您的所有三个测试文档进行点击...上面是否可能缺少某些内容?
-
如果我使用快速查询 API,我也会得到三个点击,例如
curl -sS localhost:9200/my_index/_search?q=auftrag。但是上面的脚本返回 2 个点击,我认为是因为minimum_should_match。如果这很重要,我会像这样运行 ES:docker run -it -p 9200:9200 docker.elastic.co/elasticsearch/elasticsearch:6.1.1
标签: elasticsearch highlighting