搜索数据时弹出搜索错误请求

时间:2017-11-28 11:59:34

标签: php elasticsearch

我在json下面将数据搜索到弹性搜索数组中,但我总是得到异常而不是下面的搜索响应是异常并搜索我希望用户搜索的json数据

 {
        "index":"people",
        "type":"people_list",
        "from":0,
        "size":"20",
        "body":{
          "query":{
              "bool":{
                  "must_not":{
                      "terms":{"id":"2"}
                   },
                  "must":{
                      "terms":{"is_live":1}
                  }
               }
            }
        }
   }

异常

<pre>{"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[QPbfeXzKTpOjM53S5Y09ng][people][0]: SearchParseException[[people][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"bool\":{\"must_not\":{\"terms\":{\"id\":\"2\"}},\"must\":{\"terms\":{\"is_live\":1}}}}}]]]; nested: QueryParsingException[[people] [terms] query does not support [id]]; }{[QPbfeXzKTpOjM53S5Y09ng][people][1]: SearchParseException[[people][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"bool\":{\"must_not\":{\"terms\":{\"id\":\"2\"}},\"must\":{\"terms\":{\"is_live\":1}}}}}]]]; nested: QueryParsingException[[people] [terms] query does not support [id]]; }{[QPbfeXzKTpOjM53S5Y09ng][people][2]: SearchParseException[[people][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"bool\":{\"must_not\":{\"terms\":{\"id\":\"2\"}},\"must\":{\"terms\":{\"is_live\":1}}}}}]]]; nested: QueryParsingException[[people] [terms] query does not support [id]]; }{[QPbfeXzKTpOjM53S5Y09ng][people][3]: SearchParseException[[people][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"bool\":{\"must_not\":{\"terms\":{\"id\":\"2\"}},\"must\":{\"terms\":{\"is_live\":1}}}}}]]]; nested: QueryParsingException[[people] [terms] query does not support [id]]; }{[QPbfeXzKTpOjM53S5Y09ng][people][4]: SearchParseException[[people][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"bool\":{\"must_not\":{\"terms\":{\"id\":\"2\"}},\"must\":{\"terms\":{\"is_live\":1}}}}}]]]; nested: QueryParsingException[[people] [terms] query does not support [id]]; }]","status":400}

弹性搜索版

{
  "status" : 200,
  "name" : "Data",
  "cluster_name" : "ElasticSearch",
  "version" : {
    "number" : "1.7.2",
    "build_hash" : "e43676b1385b8125d647f593f7202acbd816e8ec",
    "build_timestamp" : "2015-09-14T09:49:53Z",
    "build_snapshot" : false,
    "lucene_version" : "4.10.4"
  },
  "tagline" : "You Know, for Search"
}

1 个答案:

答案 0 :(得分:1)

如果您要使用terms,则该值应为数组。

您有两个选择:

  1. terms更改为term

    {"term": { "id":"2" }}
    
  2. terms的值更改为如下数组:

    {"terms":{"id":["2"]}}