Rizwan Saleem
Rizwan Saleem

Reputation: 896

Elastic search bad request in while searching data

I have below json to serach data into elastic search array but I always get exception instead of search response below is exception and search json data that I want to user for searching

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

Exception

<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}

Elastic search version

{
  "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"
}

Upvotes: 0

Views: 1164

Answers (1)

Diyarbakir
Diyarbakir

Reputation: 2099

If you're going to use terms the value should be an array.

You have 2 options:

  1. Change terms to term

    {"term": { "id":"2" }}
    
  2. Change the value of terms to an array like this:

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

Upvotes: 2

Related Questions