Elasticsearch突出显示:查询使用"copy_to"创建的自定义"_all"字段 [英] Elasticsearch highlighting: "multi-match" query on custom "_all"-fields created with "copy_to"
问题描述
(Elasticsearch 5.2.2)
(Elasticsearch 5.2.2)
我在突出显示以正常工作方面遇到了一些麻烦.我的映射有2个通过 copy_to 创建的自定义创建的 _all 字段 myall1 和 myall2 :
I'm having some trouble getting highlighting to work correctly. My mapping has 2 custom created _all-fields myall1 and myall2 that are created via 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:
Now I'm running a multi_match-query that boosts myall1 by 3:
POST /myindex/mytype/_search
{
"query": {
"bool": {
"must": {
"multi_match": {
"fields": ["myall1^3", "myall2"],
"type": "cross_fields",
"query": "example text",
"operator": "and"
}
}
}
}
}
这很好.问题是我无法在结果中突出显示原始源字段.我将以下内容添加到查询中,方法与在ES-docs"_all示例"中完成的方式相同:
This works quite well. The problem is that I cannot highlight the original source-fields in the result. I'm adding the following to the query the same way it is done in the ES-docs "_all example":
,
"highlight": {
"pre_tags": ["<span class='highlight'>"],
"post_tags": ["</span>"],
"fields": {
"*": {"require_field_match": false}
}
}
这仅使我突出显示"myall1"和"myall2",而不是原始字段"field1"和"field2".
This gives me only the highlighting in "myall1" and "myall2", NOT in the original fields "field1" and "field2".
如果我通过使用_all-field做类似的事情,那么一切都会按预期进行.主要区别在于:我使用的是 multi_match ,而示例使用的是 query_string .玩"store":true和"analyzer":"standard"并没有帮助.
If I do something similar by using the _all-field, everything works as expected. The main difference is: I'm using multi_match while the examples use query_string. Playing with "store":true and "analyzer":"standard" didn't help.
由于我的实际文档使用的嵌套对象必须是可搜索的,所以我可能无法执行完全不同的查询方法.
As my actual document uses nested-objects that must be searchable, I might not be able to do a completely different query-approach.
这是设计使然还是我缺少什么?相反,使用"_all"字段不允许我以尝试实现的方式提升结果.
Is this by design or am I missing something? Using the "_all"-field instead would not allow me to boost results the way I'm trying to implement it.
推荐答案
修复了该问题.似乎突出显示原始字段要求他们使用与复制到"目标字段相同的分析器.否则,它们根本不会出现.
Fixed it. Seems that highlighting of the original fields requires them to use the same analyzer as the "copy-to" target field does. Otherwise they simply won't show up.
我之前使用的是"analyzer":"keyword",因为我不打算在这些字段上进行实际查询.现在一切都按预期进行.
I was using "analyzer":"keyword" before as I did not plan to do actual queries on those fields. Now everything works as expected.
这篇关于Elasticsearch突出显示:查询使用"copy_to"创建的自定义"_all"字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!