elasticsearch ElasticSearch突出显示与过滤器查询,elasticsearch,filter,highlight,elasticsearch,Filter,Highlight" /> elasticsearch ElasticSearch突出显示与过滤器查询,elasticsearch,filter,highlight,elasticsearch,Filter,Highlight" />

elasticsearch ElasticSearch突出显示与过滤器查询

elasticsearch ElasticSearch突出显示与过滤器查询,elasticsearch,filter,highlight,elasticsearch,Filter,Highlight,我有以下查询,但highlight不起作用 { "query": { "filtered" : { "filter" : { "or" : { "filters" : [ { "query": { "multi_match":{ "query":"time", "fields":[

我有以下查询,但highlight不起作用

{
  "query": {
    "filtered" : {
      "filter" : {
        "or" : {
          "filters" : [
            {
            "query": { 
              "multi_match":{
                "query":"time",
                "fields":[
                        "display_name_en","display_name_pa","display_name_pr",
                        "icon_class","in_sidemenu","model_name","name",
                        "table_name"
                ],
                "operator":"OR"
              } 
            }
          },
          {
            "terms":{
              "created_by.id":["11","13","14","16"],
              "_name" : "created_by"
            }       
          },
          {
            "range":{
              "created_at":{
                "gte":"2016-01-27",
                "lte":"2016-03-21",
                "format":"YYYY-MM-dd"
              }
            }
          } 
        ],
        "_name" : "or"
      }
    } 
  }
},
"highlight": {
    "fields" : {
        "name" : {}
    }
}
}
结果是这样的:

{
  "took": 3,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
 },
 "hits": {
  "total": 1,
  "max_score": 1,
  "hits": [
     {
        "_index": "promote_kmp",
        "_type": "resources",
        "_id": "569e0d84684cc",
        "_score": 1,
        "_source": {
           "id": 106,
           "name": "Last time First Update",
           "display_name_en": "Last time",
           "display_name_pr": "Last time",
           "display_name_pa": "Last time",
           "table_name": "Last time",
           "model_name": "Last time",
           "in_sidemenu": "0",
           "icon_class": "Last time",
           "created_at": "2016-01-18 09:40:51",
           "created_by": null,
           "updated_at": "2016-01-19 14:48:44",
           "updated_by": {
              "id": 6,
              "first_name": "Laili",
              "last_name": "Hamta",
              "last_activity": "2016-01-19 14:48:44",
              "roles": [
                 {
                    "id": 1,
                    "name": "admin",
                    "created_at": "2015-09-06 15:19:15",
                    "updated_at": "2015-09-06 15:19:15",
                    "pivot": {
                       "user_id": 6,
                       "role_id": 1
                    }
                 }
              ]
           }
        },
        "matched_queries": [
           "or"
        ]
     }
  ]
 }
}
正如您看到的,结果中没有任何highlight关键字,那么这个查询有什么错误,为什么highlight不起作用?但是,如果我将
多重匹配
部分放在
过滤器前面:{}
它正在工作,在这种情况下,我如何使用
操作符?

感谢您的帮助。

查询的问题是,您只能过滤结果,
高亮显示
只能处理
查询。您还可以注意到,由于只应用了
过滤器,所以每个文档的
得分都为1。您需要像这样重写查询

{
  "query": {
    "bool": {
      "should": [
        {
          "multi_match": {
            "query": "time",
            "fields": [
              "display_name_en",
              "display_name_pa",
              "display_name_pr",
              "icon_class",
              "in_sidemenu",
              "model_name",
              "name",
              "table_name"
            ]
          }
        },
        {
          "terms": {
            "created_by.id": [
              "11",
              "13",
              "14",
              "16"
            ],
            "_name": "created_by"
          }
        },
        {
          "range": {
            "created_at": {
              "gte": "2016-01-27",
              "lte": "2016-03-21",
              "format": "YYYY-MM-dd"
            }
          }
        }
      ]
    }
  },
  "highlight": {
    "fields": {}
  }
}

或过滤器
转换为
bool should子句
,高亮显示现在可以工作。

查询的问题是,您只过滤结果,
高亮显示
只对
查询
起作用。您还可以注意到,由于只应用了
过滤器,所以每个文档的
得分都为1。您需要像这样重写查询

{
  "query": {
    "bool": {
      "should": [
        {
          "multi_match": {
            "query": "time",
            "fields": [
              "display_name_en",
              "display_name_pa",
              "display_name_pr",
              "icon_class",
              "in_sidemenu",
              "model_name",
              "name",
              "table_name"
            ]
          }
        },
        {
          "terms": {
            "created_by.id": [
              "11",
              "13",
              "14",
              "16"
            ],
            "_name": "created_by"
          }
        },
        {
          "range": {
            "created_at": {
              "gte": "2016-01-27",
              "lte": "2016-03-21",
              "format": "YYYY-MM-dd"
            }
          }
        }
      ]
    }
  },
  "highlight": {
    "fields": {}
  }
}

或过滤器
转换为
bool-shoul子句
,高亮显示现在可以工作了。

谢谢,它可以工作了。但另一个问题是,如果我想突出显示所有匹配的字段,我该如何做?所有字段是什么意思?您使用的是哪个版本的ES?根据示例,我想在
多匹配
字段中搜索
time
术语,现在假设
time
字符串位于
name,display\u name\u pr
中,因此在
highlight
部分中不指定这些字段,我如何说query只突出显示这些字段,如果在中找到该
时间
字符串?我从1.6开始使用,现在发生了什么?尝试类似于
“highlight”:{“fields”:{“*”:{},“require_field_match”:true}
的方法,或者您也可以使用该选项专门指定特定的查询,只要您知道它正在工作。但另一个问题是,如果我想突出显示所有匹配的字段,我该如何做?所有字段是什么意思?您使用的是哪个版本的ES?根据示例,我想在
多匹配
字段中搜索
time
术语,现在假设
time
字符串位于
name,display\u name\u pr
中,因此在
highlight
部分中不指定这些字段,我如何说query只突出显示这些字段,如果在中找到该
时间
字符串?我从1.6开始使用,现在发生了什么?尝试类似于
“highlight”:{“fields”:{“*”:{},“require_field_match”:true}
,或者您也可以使用该选项专门指定特定的查询