gpt4 book ai didi

elasticsearch - 如何在 Elasticsearch v5 中突出显示嵌套对象命中

转载 作者:行者123 更新时间:2023-11-29 02:57:35 26 4
gpt4 key购买 nike

我试图让嵌套查询的命中返回突出显示。根据文档,这是可能的。文档说:

The parent/child and nested features allow the return of documents that have matches in a different scope. In the nested case, documents are returned based on matches in nested inner objects. The inner hits feature returns per search hit in the search response additional nested hits that caused a search hit to match in a different scope. Inner hits can be used by defining an inner_hits definition on a nested, has_child or has_parent query and filter. Inner hits also supports the following per document features:

'Highlighting', 'Explain Source', 'filtering', 'Script fields', 'Doc value', 'fields', 'Include versions'.

https://www.elastic.co/guide/en/elasticsearch/reference/5.0/search-request-inner-hits.html#nested-inner-hits

但是,我无法根据以下映射和查询使它正常工作。谁能解释我哪里出错了?

注意:我特指的是嵌套类型,而不是 parent_child。

我发现它仅在将 referenceIdValue 和 ReferenceIdType 从关键字更改为文本时才有效,但显然这不是我想要的。 ES 文档说:

"The field name supports wildcard notation. For example, using comment_* will cause all text and keyword fields (and string from versions before 5.0) that match the expression to be highlighted. Note that all other fields will not be highlighted." https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-highlighting.html#_highlight_query I'm thinking this may be a bug?

非常感谢。

映射:

{
"entity": {
"dynamic_templates": [{
"catch_all": {
"match_mapping_type": "*",
"mapping": {
"type": "text",
"store": true,
"analyzer": "phonetic_index",
"search_analyzer": "phonetic_query"
}
}
}],
"_all": {
"enabled": false
},
"properties": {
"entityName": {
"type": "text",
"store": true,
"analyzer": "indexed_index",
"search_analyzer": "indexed_query",
"referenceIds": {
"type": "nested",
"properties": {
"referenceIdValue": {
"type": "keyword",
"norms": true,
"store": true
},
"referenceIdType": {
"type": "keyword",
"store": true,
"norms": true
}
}
},
"isPublished": {
"type": "boolean",
"store": true
}
}
}
}

查询:

curl -XGET "127.0.0.1:9200/test/entity/_search?pretty" -d"
{
"query": {
"bool": {
"filter": {
"term": {
"isPublished": "true"
}
},
"must": [
[{
"nested": {
"query": {
"bool": {
"must": [
[{
"term": {
"referenceIds.referenceIdValue": "123456"
}
}, {
"term": {
"referenceIds.referenceIdType": "ENCO"
}
}]
]
}
},
"inner_hits": {
"highlight": {
"fields": {
"referenceIds.referenceIdValue": {},
"referenceIds.referenceIdType": {}
}
}
},
"path": "referenceIds"
}
}]
]
}
}
}"

结果:

{
"took": 99,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 14.319202,
"hits": [{
"_index": "test",
"_type": "entity",
"_id": "3423631",
"_score": 14.319202,
"_source": {
"entityName": "Test Entity",
"referenceIds": [{
"referenceIdValue": "AAAABBBB",
"referenceIdType": "SULA"
}, {
"referenceIdValue": "123456",
"referenceIdType": "ENCO"
}]
},
"inner_hits": {
"referenceIds": {
"hits": {
"total": 1,
"max_score": 14.319202,
"hits": [{
"_nested": {
"field": "referenceIds",
"offset": 3
},
"_score": 14.319202,
"_source": {
"referenceIdValue": "123456",
"referenceIdType": "ENCO"
}
}]
}
}
}
}]
}
}

最佳答案

我认为这是因为在查询的突出显示部分,您需要设置相对于嵌套文档的路径。试试这个:

                "inner_hits": {
"highlight": {
"fields": {
"referenceIdValue": {},
"referenceIdType": {}
}
}
},

关于elasticsearch - 如何在 Elasticsearch v5 中突出显示嵌套对象命中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41717963/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com