如何同时执行Elastsearch multi_match和BOOL?

时间:2018-10-02 02:20:36

标签: elasticsearch

我尝试使用以下查询,

 {
   "query":{
      "bool":{
         "must":[
            {
               "range":{
                  "@timestamp":{
                     "from":"2018-09-01T08:35:11.000Z",
                     "to":"2018-10-01T08:35:11.000Z"
                  }
               }
            },
            "multi_match":{
               "query":"世界の人々の祝祭、第23回冬季",
               "fields":"message"
            }
         ]
      }
   },
   "from":0,
   "size":10000
}

但收到错误消息:

{
  "error" : {
    "root_cause" : [
  {
        "type" : "json_parse_exception",
        "reason" : "Unexpected character (':' (code 58)): was expecting comma to separate Array entries\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@4eacc26c; line: 21, column: 27]"
      }
  },
  "status" : 500
}

但是如果没有时间戳范围,那就可以了

"query": {
    "multi_match": {
      "query": "世界の人々の祝祭、第23回冬季",
      "fields": [
        "message"
      ]
     }
 }

请求中有什么问题?如何一起执行multi_match和BOOL?

1 个答案:

答案 0 :(得分:1)

您还需要将multi_match查询包裹在花括号中

 {
   "query":{
      "bool":{
         "must":[
            {
               "range":{
                  "@timestamp":{
                     "from":"2018-09-01T08:35:11.000Z",
                     "to":"2018-10-01T08:35:11.000Z"
                  }
               }
            },
            {
              "multi_match":{
                 "query":"世界の人々の祝祭、第23回冬季",
                 "fields":"message"
              }
            }
         ]
      }
   },
   "from":0,
   "size":10000
}