使用 FVH 突出显示 ElasticSearch 7.6.2 的正确设置是啥?
Posted
技术标签:
【中文标题】使用 FVH 突出显示 ElasticSearch 7.6.2 的正确设置是啥?【英文标题】:What is the correct setup for ElasticSearch 7.6.2 highlighting with FVH?使用 FVH 突出显示 ElasticSearch 7.6.2 的正确设置是什么? 【发布时间】:2020-07-17 14:29:07 【问题描述】:如何使用快速矢量荧光笔在巨大的文档中正确设置高亮搜索词?
我已经尝试了索引的文档和以下设置(作为 Python 文字,注释了替代设置,我也尝试过,有存储和没有存储):
"settings":
"number_of_shards": 1,
"number_of_replicas": 0
,
"mappings":
"members":
"dynamic": "strict",
"properties":
"url":
"type": "text",
"term_vector": "with_positions_offsets",
#"index_options": "offsets",
"store": True
,
"title":
"type": "text",
#"index_options": "offsets",
"term_vector": "with_positions_offsets",
"store": True
,
"content":
"type": "text",
#"index_options": "offsets",
"term_vector": "with_positions_offsets",
"store": True
通过以下查询完成搜索(同样,评论的地方被逐一尝试,在某些组合中):
"query":
"multi_match":
"query": term,
"fields": ["url", "title", "content"]
,
,
"_source":
#"includes": ["url", "title", "_id"],
# "excludes": ["content"]
,
"highlight":
"number_of_fragments": 40,
"fragment_size": 80,
"fields":
"content": "matched_fields": ["content"],
#"content": "type": "fvh", "matched_fields": ["content"],
#"title": "type": "fvh", "matched_fields": ["title"],
问题是,当不使用 FVH 时,ElasticSearch 会抱怨“内容”字段太大。 (而且我不想增加允许的大小)。当我添加“fvh”类型时,ES 抱怨需要术语向量:即使我已经通过查询文档信息(偏移量、开始等)检查了这些术语向量:
字段 [content] 应使用带有位置的术语向量进行索引 与快速矢量荧光笔一起使用的偏移量
好像是这样的:
-
当我省略
"type": "fvh"
时,它不会被使用,即使文档中提到它是 "term_vector": "with_positions_offsets" 时的默认值。
我可以在索引中看到术语向量,但 ES 没有找到它们。 (间接地,当使用术语向量进行索引时,索引几乎是原来的两倍)
所有试验都包括删除旧索引并重新添加。
它也很危险,只有在遇到大文件时才会失败。文档较小的查询有亮点。
在 ElasticSearch 7 免费版中设置亮点的正确方法是什么(我在 Ubuntu 下尝试使用供应商提供的二进制 deb)?
【问题讨论】:
【参考方案1】:fvh 荧光笔使用 Lucene Fast Vector 荧光笔。此荧光笔可用于映射中 term_vector
设置为 with_positions_offsets
的字段。快速矢量荧光笔需要将term_vector
设置为with_positions_offsets
,这会增加索引的大小。
您可以为您的字段定义如下映射。
"mappings":
"properties":
"text":
"type": "text",
"term_vector": "with_positions_offsets"
查询高亮字段时,需要使用"type" : "fvh"
默认情况下,文本字段将使用快速矢量突出显示,因为术语向量已启用。
【讨论】:
以上是关于使用 FVH 突出显示 ElasticSearch 7.6.2 的正确设置是啥?的主要内容,如果未能解决你的问题,请参考以下文章
使用 Elasticsearch,我可以为不同的匹配标记使用不同的 HTML 标签突出显示吗?