虽然是Lucene逻辑结构,但我试图让我的嵌套字段在其内容中出现某些搜索结果时突出显示。
这是来自Elasticsearch 文档的解释(映射嵌套类型`)
内部实施
在内部,嵌套对象被索引为附加文档,但是,由于可以保证它们在同一个“块”内被索引,它允许极快地与父文档连接。
在对索引执行操作时(例如使用 match_all 查询进行搜索),这些内部嵌套文档会自动被屏蔽掉,并且在使用嵌套查询时它们会冒泡。
因为嵌套文档总是被父文档屏蔽,嵌套文档永远不能在嵌套查询范围之外访问。例如,可以在嵌套对象内的字段上启用存储字段,但无法检索它们,因为存储字段是在嵌套查询范围之外获取的。
0. 就我而言
我有一个Elasticsearch索引,其中包含如下映射:
{
"my_documents": {
"dynamic_date_formats": [
"dd.MM.yyyy",
"yyyy-MM-dd",
"yyyy-MM-dd HH:mm:ss"
],
"index_analyzer": "Analyzer2_index",
"search_analyzer": "Analyzer2_search_decompound",
"_timestamp": {
"enabled": true
},
"properties": {
"identifier": {
"type": "string"
},
"description": {
"type": "multi_field",
"fields": {
"sort": {
"type": "string",
"index": "not_analyzed"
},
"description": {
"type": "string"
}
}
},
"files": {
"type": "nested",
"include_in_root": true,
"properties": {
"content": {
"type": "string",
"include_in_root": true
}
}
},
"and then some other": "normal string fields"
}
}
}
我正在尝试执行这样的查询:
{
"size": 100,
"query": {
"bool": {
"should": [
{
"nested": {
"path": "files",
"query": {
"bool": {
"should": {
"match": {
"content": {
"query": "burpcontrol",
"minimum_should_match": "85%"
}
}
}
}
}
}
},
{
"match": {
"description": {
"query": "burpcontrol",
"minimum_should_match": "85%"
}
}
},
{
"match": {
"identifier": {
"query": "burpcontrol",
"minimum_should_match": "85%"
}
}
} ]
}
},
"highlight": {
"pre_tags": [
"<span style=\"background-color: yellow\">"
],
"post_tags": [
"</span>"
],
"order": "score",
"no_match_size": 100,
"fragment_size": 50,
"number_of_fragments": 3,
"require_field_match": true,
"fields": {
"files.content": {},
"description": {},
"identifier": {}
}
}
}
我遇到的问题是:
1.require_field_match
如果我使用"require_field_match": false
我会得到它,即使突出显示不适用于嵌套字段,搜索词也会在所有字段中突出显示。这是我实际使用的解决方案,但性能很糟糕。对于 50 个文档,我的查询需要 25 秒。100 个文档大约 50 秒。10 个文件 5 秒。
如果我从突出显示中删除嵌套字段,一切都会像光一样快!
2 .include_in_root
我想要我的嵌套字段的扁平版本(以便将它们存储为普通对象/字段。为此,我应该指定
“文件”:{“类型”:“嵌套”,“ include_in_root ”:真,...
但我不知道为什么,在重新索引后,我在文档根目录中看不到任何额外的展平字段(而我期待类似的东西"files.content":["content1", "content2", "..."]
)。
如果它可以工作,则可以访问(在展平的字段中)嵌套字段的内容,并对其执行突出显示。