【问题标题】:ElasticSearch Highlighting not doing what I would expectElasticSearch Highlighting 没有达到我的预期
【发布时间】:2016-09-05 23:51:03
【问题描述】:

我在我的 Elasticsearch 查询中添加了高亮显示,但是,它似乎在我认为不应该的字段上高亮显示。

这是我的查询:

{
  "from": 0,
  "size": 100,
  "sort": [
    {
      "entityName.raw": {
        "order": "asc"
      }
    }
  ],
  "highlight": {
    "pre_tags": [
      "<span class=\"highlighter\">"
    ],
    "post_tags": [
      "</span>"
    ],
    "fields": {
      "entityName": {},
      "friendlyUrl": {},
      "sentBy": {}
    },
    "require_field_match": true
  },
  "query": {"bool":{"must":[{"match":{"_all":{"query":"test","operator":"and"}}}]}},
  "filter": {
    "bool": {
      "must": [
        {
          "term": {
            "serviceId": "0b6d064d-1430-4b04-99f7-c30dc03860fc"
          }
        },
        {
          "term": {
            "subscriptionId": "a29f30e6-f44b-42cc-82c4-f7cb98cb44ef"
          }
        },
        {
          "term": {
            "subscriptionType": 0
          }
        },
        {
          "terms": {
            "entityType": [
              "4"
            ]
          }
        }
      ]
    }
  }
}

这是我服务器上添加突出显示的一行:

 desc.Highlight(h => h.PreTags("<span class=\"highlighter\">").PostTags("</span>").OnFields(ff => ff.OnField("entityName"), fff => fff.OnField("friendlyUrl"), x => x.OnField("sentBy")));

此查询应该找到与keywords 字段上的通配符john* 和正则表达式.* 匹配的任何文档(我需要检查keywords != "")。问题是当结果返回时,荧光笔响应返回并突出显示文档中的所有内容

就好像正则表达式忽略了这样一个事实,即我告诉它只查看keywords 字段,而是匹配所有字段。我希望荧光笔仅在与 .* 匹配时突出显示 keywords 字段,但它不是...

我做错了什么?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    "require_field_match": true 添加到您的荧光笔中以强制它与查询的字段匹配。

    【讨论】:

    • 我已经读过这个,但文档说默认是true,所以我认为这无关紧要。我还是会尝试一下,以防万一。 elastic.co/guide/en/elasticsearch/reference/current/…
    • 好的。告诉我进展如何。
    • 所以我添加了这一点,它确实使这个查询的突出显示消失了,但是它似乎也使它对我所有其他查询也消失了......现在甚至没有突出显示虽然应该。
    • 嗯,能提供当前的完整查询吗?
    • 是的,让我尝试使用 Fiddler 获取它。我的一半查询是在客户端完成的,一半是在服务器端完成的(C#),所以我无法轻松访问它。
    猜你喜欢
    • 2021-10-15
    • 1970-01-01
    • 1970-01-01
    • 2012-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-27
    相关资源
    最近更新 更多