- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 elastic search 7.10,喜欢通过通配符搜索分析字段来查找文档,并在文本中突出显示这些文档。但这不起作用。
文档可以包含以下示例:“The color of the car is black.”
我希望得到 car
和 black
被标记的结果。
我有以下映射:
"text": {
"type": "text",
"store": true,
"term_vector": "with_positions_offsets",
"analyzer": "my_analyzer",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 8000
},
"wc" :{
"type": "wildcard"
}
}
},
我使用以下查询:
{
"query": {
"bool": {
"should": [
{
"match": {"text": "car"}
},
{
"wildcard": { "text.wc": { "value": "bl*" } }
}
]
}
},
"fields": ["text", "text.wc"],
"highlight": {
"pre_tags": [
"<span class='marker'>"
],
"post_tags": [
"</span>"
],
"type": "fvh",
"fields": {
"*": {
"pre_tags": [
"<em>"
],
"post_tags": [
"</em>"
]
}
},
"require_field_match": true
}
}
查询结果集仅包含 text
- 字段的高亮显示,但不包含 text.wc
字段的高亮显示。我还尝试了一个单独的通配符字段,它不是 text
的子字段,但这也不起作用。我还注意到,_source
- 需要将字段设置为 enabled
,即使所有字段都设置为存储,否则我会收到 Unable to retrieve the requested [字段]
消息。
问题:如何为 wildcrad 搜索词获取突出显示的文本?
最佳答案
我找到了解决方案,并愿意亲自回答我的问题,以防有人遇到同样的问题。
答案是,通配符、突出显示和文本分析(如词干提取)不适用于 match
和 wildcard
- 像上面这个查询一样。
但是:您可以使用 query_string
而不是 match
和 wildcard
。这是弹性查询 DSL 的一部分,但不幸的是它没有在此处列出:https://www.elastic.co/guide/en/elasticsearch/reference/7.16/query-dsl.html
在我看来,这个非常重要的功能位于此处更深的 2 个基本点击/级别:https://www.elastic.co/guide/en/elasticsearch/reference/7.16/query-dsl-query-string-query.html
query_string
允许您在分析字段上执行所有搜索和突出显示操作,就像来自 solr
的人在查询中所做的那样。
一个例子看起来像这样:
"query": {
"bool": {
"should": [
{
"query_string": {
"fields": [
"text"
],
"query": "car and bl*"
}
]
}
}
"highlight": {
"pre_tags": [
"<span class='marker'>"
],
"post_tags": [
"</span>"
],
"type": "fvh",
"fields": {
"*": {
"pre_tags": [
"<em>"
],
"post_tags": [
"</em>"
]
}
},
"require_field_match": true
}
}
关于elasticsearch - Elasticsearch : Highlight wildcrad search result,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70835954/
我使用 elastic search 7.10,喜欢通过通配符搜索分析字段来查找文档,并在文本中突出显示这些文档。但这不起作用。 文档可以包含以下示例:“The color of the car is
我是一名优秀的程序员,十分优秀!