ElasticSearch突出显示没有做我期望的事情

时间:2016-05-10 20:11:00

标签: elasticsearch

我在我的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")));

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

好像正则表达式忽略了我告诉它仅查看keywords字段而是在所有字段上匹配的事实。如果匹配keywords,我希望荧光笔只突出显示.*字段,但它不是......

我做错了什么?

1 个答案:

答案 0 :(得分:1)

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

相关问题