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
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.
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.
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.
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.
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"
}
}
]
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With