【发布时间】:2017-06-30 14:51:37
【问题描述】:
(弹性搜索 5.2.2)
我在突出显示正常工作时遇到了一些问题。 我的映射有 2 个自定义创建的 _all-字段 myall1 和 myall2,它们是通过 copy_to 创建的:
"mytype": {
"_all": {
"enabled": false
},
"properties": {
"myall": {
"type": "text",
"analyzer": "standard",
"store": true
},
"myall2": {
"type": "text",
"analyzer": "standard",
"store": true
},
"field1": {
"type": "text",
"copy_to": "myall1",
"analyzer": "keyword"
},
"field2": {
"type": "text",
"copy_to": "myall2",
"analyzer": "keyword"
}
}
一个文档应该是这样的:
{
"field1": "example text",
"field2": "another text"
}
现在我正在运行 multi_match-查询,将 myall1 提升 3:
POST /myindex/mytype/_search
{
"query": {
"bool": {
"must": {
"multi_match": {
"fields": ["myall1^3", "myall2"],
"type": "cross_fields",
"query": "example text",
"operator": "and"
}
}
}
}
}
这很好用。问题是我无法在结果中突出显示 original 源字段。 我将以下内容添加到查询中,就像在 ES-docs“_all 示例”中一样:
,
"highlight": {
"pre_tags": ["<span class='highlight'>"],
"post_tags": ["</span>"],
"fields": {
"*": {"require_field_match": false}
}
}
这只会突出显示“myall1”和“myall2”,而不是原始字段“field1”和“field2”。
如果我使用 _all 字段做类似的事情,一切都会按预期工作。 主要区别在于:我使用的是 multi_match,而示例使用的是 query_string。 玩 "store":true 和 "analyzer":"standard" 没有帮助。
由于我的实际文档使用必须可搜索的嵌套对象,我可能无法执行完全不同的查询方法。
这是设计使然还是我遗漏了什么? 改用“_all”字段不会让我以尝试实现它的方式提升结果。
【问题讨论】:
标签: elasticsearch