Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch: how can I filter on a boolean field

I am new to Elasticsearch. I have a mapping which has a boolean field.

I need to filter on this field, and I am not sure which filter to use. Based on my research, I probably should use term filter. Is this correct? To me, the term filter seems to be designed for string fields.

Thanks!

like image 914
curious1 Avatar asked Jul 20 '14 15:07

curious1


People also ask

What is boolean query Elasticsearch?

Boolean, or a bool query in Elasticsearch, is a type of search that allows you to combine conditions using Boolean conditions. Elasticsearch will search the document in the specified index and return all the records matching the combination of Boolean clauses.

When should I use bool query Elasticsearch?

Boolean queries in Elasticsearch are a popular query type because of their versatility and ease of use. Boolean queries, or bool queries, find or match documents by using boolean clauses. For the vast majority of cases, the filtering clause will be used because it can be cached for faster search times.

What is bool query?

Boolean queryedit. A query that matches documents matching boolean combinations of other queries. The bool query maps to Lucene BooleanQuery . It is built using one or more boolean clauses, each clause with a typed occurrence.

Should VS must Elasticsearch?

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.


1 Answers

Yes, a term filter is the correct choice: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-term-filter.html

Think of the boolean field as containing either the term T or the term F, so a term filter is appropriate.

See these two discussions: http://elasticsearch-users.115913.n3.nabble.com/Which-filter-could-be-used-on-boolean-field-td4035426.html and http://elasticsearch-users.115913.n3.nabble.com/Simple-equality-filter-td3063743.html

like image 139
John Petrone Avatar answered Sep 18 '22 10:09

John Petrone