Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error : [bool] query does not support [term]

I am using Elasticsearch version 2.3.2. I am trying to use filter on boolean query, but I am getting an error:

"type": "query_parsing_exception",
            "reason": "[bool] query does not support [term]",

My elasticsearch query is:

GET index_name/_search
{
  "query": {
    "bool": {
      "must": [
        {"match": {
          "title": "white"
        }},
        {
          "match": {
            "newContent": "white"
          }
        }
      ],
      "filter": {
        "term": {
          "default_collection": "true"
        }
      }
      ,"term":{
        "wiki_collection": "true"
      }
    }
  }
}

I am not sure what the problem is. I might be missing something

like image 231
Rose Avatar asked Jun 28 '16 16:06

Rose


People also ask

What is a bool query?

The bool query lets you combine multiple search queries with boolean logic. You can use boolean logic between queries to either narrow or broaden your search results. The bool query is a go-to query because it allows you to construct an advanced query by chaining together several simple ones.

What is term query in Elasticsearch?

Term queryedit. Returns documents that contain an exact term in a provided field. You can use the term query to find documents based on a precise value such as a price, a product ID, or a username.

Should bool query?

Now in a bool query: must means: Clauses that must match for the document to be included. should means: If these clauses match, they increase the _score ; otherwise, they have no effect. They are simply used to refine the relevance score for each document.

Should must not Elasticsearch?

Using must_not tells Elasticsearch that document matches cannot include any of the queries that fall under the must_not clause. should – It would be ideal for the matching documents to include all of the queries in the should clause, but they do not have to be included. Scoring is used to rank the matches.


1 Answers

You need to move both term filters inside a filter array (and use POST instead of GET when sending a payload):

POST index_name/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "title": "white"
          }
        },
        {
          "match": {
            "newContent": "white"
          }
        }
      ],
      "filter": [
        {
          "term": {
            "default_collection": "true"
          }
        },
        {
          "term": {
            "wiki_collection": "true"
          }
        }
      ]
    }
  }
}
like image 189
Val Avatar answered Nov 15 '22 08:11

Val