弹性搜索突出显示不适用于过滤器查询

elastic search highlight not working with filter query

我这辈子都无法强调这一点。似乎弹性搜索在突出显示过滤子句中提到的字段方面被打破了。下面的查询只是没有突出显示。这是 Elastic 的问题吗?我该怎么做才能完成这项工作?

    {
  "query": {
    "filtered": {
      "query": {
        "bool": {
          "must": [
            {
              "term": {
                "language": "Austrian"
              }
            }
          ]
        }
      },
      "filter": {
        "and": [
          {
            "query": {
              "query_string": {
                "fields": [
                  "standard_analyzed_name",
                  "standard_analyzed_message"
                ],
                "query": "Arnold AND Schwarz"
              }
            }
          }
        ]
      }
    }
  },
  "size": 20,
  "sort": [
    {
      "total_interactions": {
        "order": "desc"
      }
    }
  ],
  "highlight": {
    "fields": {
      "standard_analyzed_name": {
        "pre_tags": [
          "<strong>"
        ],
        "post_tags": [
          "</strong>"
        ],
        "fragment_size": 500,
        "number_of_fragments": 1
      },
      "standard_analyzed_message": {
        "pre_tags": [
          "<strong>"
        ],
        "post_tags": [
          "</strong>"
        ],
        "fragment_size": 500,
        "number_of_fragments": 1
      }
    }
  }
}

更新

上面的查询在弹性搜索 2.0.0 中突出显示 - Yayyy

好吧,简单地说,您的 queryfilter 部分互换了。你的 query_string 应该放在 query 部分里面, term 应该放在 filter 部分里面,然后一切都会好起来的,你会看到突出显示的字段。

{
   "query": {
      "filtered": {
         "query": {
            "query_string": {
               "fields": [
                  "standard_analyzed_name",
                  "standard_analyzed_message"
               ],
               "query": "arnold"
            }
         },
         "filter": {
            "term": {
               "language": "austrian"
            }
         }
      }
   },
   "size": 20,
   "sort": [
      {
         "total_interactions": {
            "order": "desc"
         }
      }
   ],
   "highlight": {
      "fields": {
         "standard_analyzed_name": {
            "pre_tags": [
               "<strong>"
            ],
            "post_tags": [
               "</strong>"
            ],
            "fragment_size": 500,
            "number_of_fragments": 3
         },
         "standard_analyzed_message": {
            "pre_tags": [
               "<strong>"
            ],
            "post_tags": [
               "</strong>"
            ],
            "fragment_size": 500,
            "number_of_fragments": 3
         }
      }
   }
}