gpt4 book ai didi

python - 基于 elasticsearch 中的 term 或 bool 查询匹配突出显示

转载 作者:行者123 更新时间:2023-11-28 18:34:06 25 4
gpt4 key购买 nike

我有两个问题。

{'bool':
{'must':
{ 'terms': 'metadata.loc':['ten','twenty']}
{ 'terms': 'metadata.doc':['prince','queen']}
}
{'should':
{ 'match': 'text':'kingdom of dreams'}
}
},
{'highlight':
{'text':
{'type':fvh,
'matched_fields':['metadata.doc','text']
}
}
}

有两个问题?

  1. 为什么带有 should query match 的文档被高亮显示,而只有 must term match 的文档没有被高亮显示。

  2. 有没有什么办法可以提到上面术语查询特定的高亮条件?

这意味着 { 'terms': 'metadata.loc':['ten','twenty']} 的突出显示条件

以及 { 'terms': 'metadata.doc':['prince','queen']} 的单独高亮条件

最佳答案

1) 只有带有 should 查询的文档才会被突出显示,因为您只突出显示 text 字段,这基本上是您的 should 子句。尽管您使用的是 matched_fields ,但您只考虑了 text 字段。

来自Docs

All matched_fields must have term_vector set to with_positions_offsets but only the field to which the matches are combined is loaded so only that field would benefit from having store set to yes.

此外,您还组合了两个截然不同的字段,'matched_fields':['metadata.doc','text'],再次从文档中,这很难理解

Technically it is also fine to add fields to matched_fields that don’t share the same underlying string as the field to which the matches are combined. The results might not make much sense and if one of the matches is off the end of the text then the whole query will fail.

2) 您可以使用 Highlight Query 编写特定于术语查询的突出显示条件

在查询的突出显示部分试试这个

{
"query": {
...your query...
},
"highlight": {
"fields": {
"text": {
"type": "fvh",
"matched_fields": [
"text",
"metadata.doc"
]
},
"metadata.doc": {
"highlight_query": {
"terms": {
"metadata.doc": [
"prince",
"queen"
]
}
}
},
"metadata.loc": {
"highlight_query": {
"terms": {
"metadata.loc": [
"ten",
"twenty"
]
}
}
}
}
}
}

这有帮助吗?

关于python - 基于 elasticsearch 中的 term 或 bool 查询匹配突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34104075/

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