3

我有两个疑问。

{'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 查询匹配的文档被突出显示,而只有 must 术语匹配的文档没有被突出显示。

  2. 有什么方法可以提及特定于上述术语查询的突出显示条件吗?

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

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

4

1 回答 1

1

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

文档

所有matched_fields 必须将term_vector 设置为with_positions_offsets,但仅加载匹配项组合到的字段,因此只有该字段才能受益于将store 设置为yes。

此外,您正在结合两个非常不同的领域,'matched_fields':['metadata.doc','text']这很难理解,再次来自 Docs

从技术上讲,也可以将字段添加到 match_fields 中,这些字段与组合匹配的字段不共享相同的基础字符串。结果可能没有多大意义,如果其中一个匹配项不在文本末尾,则整个查询将失败。

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

highlight在您的查询部分尝试此操作

{
  "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"
            ]
          }
        }
      }
    }
  }
}

这有帮助吗?

于 2015-12-07T04:07:35.420 回答