elasticsearch查询不支持query_string?

时间:2016-06-20 04:26:18

标签: elasticsearch query-string

ElasticSearch返回我" query_parsing_exception"," reason":" [bool]查询不支持"尝试使用以下查询查找条目时出错。我认为问题是关于" query_string"

curl -XGET '<myurl>:<myport>/index/_search?pretty' -d '
{
  "query": {
     "bool": {
        "must":[ {
           "term" : {
              "query" : "1.2.3.4",
              "fields" : [ "ip" ]
                    }
                },{
              "range" : {
               "localtime" : {
                   "from" : "2016-06-15T06:00:04.923Z",
                    "to" : "2016-06-17T17:43:04.923Z",
                     "include_lower" : true,
                     "include_upper" : true
                               }
                       }
               },
          "query_string" : {
          "default_field" : "_all",
          "query" : "word1 OR word1",

          } ]
       }
   }
 }'

为什么会出现此错误?

由于


任何帮助将不胜感激!谢谢!

1 个答案:

答案 0 :(得分:3)

通常有助于正确格式化您的查询。在你的情况下,你在query_string之前缺少大括号,并且在query_string查询之后你有一个太多的逗号。

像这样重新格式化将起作用:

curl -XGET '<myurl>:<myport>/index/_search?pretty' -d '
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "ip": "1.2.3.4"
          }
        },
        {
          "range": {
            "localtime": {
              "from": "2016-06-15T06:00:04.923Z",
              "to": "2016-06-17T17:43:04.923Z",
              "include_lower": true,
              "include_upper": true
            }
          }
        },
        {
          "query_string": {
            "default_field": "_all",
            "query": "word1 OR word1"
          }
        }
      ]
    }
  }
}'