<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Search Filter BooleanFilter help</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=121033071" />
  <subtitle>Search Filter BooleanFilter help</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=121033071</id>
  <updated>2026-06-25T04:43:52Z</updated>
  <dc:date>2026-06-25T04:43:52Z</dc:date>
  <entry>
    <title>RE: Search Filter BooleanFilter help</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121037295" />
    <author>
      <name>Russell Bohl</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121037295</id>
    <updated>2021-08-11T20:39:14Z</updated>
    <published>2021-08-11T20:35:52Z</published>
    <summary type="html">&lt;p&gt;I think you'll need to model it with nested bool queries like this
  (this is roughly Elasticsearch DSL, but not perfect syntax):&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;{
  &amp;quot;query&amp;quot;: {
    &amp;quot;bool&amp;quot; : {
        &amp;quot;should&amp;quot; : {
            &amp;quot;bool&amp;quot; : {
                &amp;quot;must&amp;quot; :  {
                    &amp;quot;term&amp;quot; : { &amp;quot;type&amp;quot; : &amp;quot;1&amp;quot; },
                    &amp;quot;term&amp;quot; : {&amp;quot;status&amp;quot; : &amp;quot;in_progress&amp;quot;}
                }
            },
            &amp;quot;bool&amp;quot; : {
                &amp;quot;must_not&amp;quot; : {
                    &amp;quot;term&amp;quot; : {&amp;quot;type&amp;quot; : &amp;quot;1&amp;quot;}
                }
            }
        }
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There's a default value of minimum_should_match=1 that's being
  leveraged to make the 2 should clauses operate like an OR condition.
  One of these 2 should clauses has to match for results to be returned. &lt;/p&gt;
&lt;p&gt;
  &lt;a
    href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html#bool-min-should-match"&gt;minimum_should_match
    docs from Elastic&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;
  &lt;a
    href="https://www.elastic.co/blog/lost-in-translation-boolean-operations-and-filters-in-the-bool-query"&gt;Older
    but useful Elastic blog on boolean queries&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Of course you then need to translate this into Liferay's Java Search
  API. But maybe that helps get you closer?&lt;/p&gt;
&lt;p&gt;Additionally, it looks like you're using the older search APIs from
  portal-kernel? Like Elasticsearch, Liferay's newer APIs don't make
  API-level distinctions between Queries and Filters:&lt;/p&gt;
&lt;p&gt;
  &lt;a
    href="https://help.liferay.com/hc/en-us/articles/360029046391-Search-Queries-and-Filters#queries-and-filters-in-liferays-search-api"&gt;Liferay
    docs on Queries and filters&lt;/a&gt;&lt;/p&gt;</summary>
    <dc:creator>Russell Bohl</dc:creator>
    <dc:date>2021-08-11T20:35:52Z</dc:date>
  </entry>
  <entry>
    <title>Search Filter BooleanFilter help</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121032970" />
    <author>
      <name>Uwe Peters</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=121032970</id>
    <updated>2021-08-16T20:15:11Z</updated>
    <published>2021-08-10T11:20:52Z</published>
    <summary type="html">&lt;p&gt;Hello there,&lt;/p&gt;
&lt;p&gt;I am trying to add a filter with a condition to my search in Liferay
  7.2 CE (Elasticsearch (Embedded), Client-Version: 7.3.0, liferay
  (7.3.0)). &lt;br /&gt; Currently I am trying to add the filter in the
  overridden postProcessContextBooleanFilter method from my
  IndexerPostProcessor class of my model.&lt;/p&gt;
&lt;p&gt;To explain my problem I came up with this example.&lt;/p&gt;
&lt;p&gt;
  &lt;u&gt;Result that should be filtered:&lt;/u&gt;
  &lt;br /&gt; Object1 = {type=1, status=&amp;quot;in_progress&amp;quot;}&lt;br /&gt;
  Object2 = {type=1, status=&amp;quot;open&amp;quot;}&lt;br /&gt; Object3 = {type=1,
  status=&amp;quot;finished&amp;quot;}&lt;br /&gt; Object4 = {type=2,
  status=&amp;quot;open&amp;quot;}&lt;br /&gt; Object5 = {type=3, status=&amp;quot;in_progress&amp;quot;}&lt;/p&gt;
&lt;p&gt;
  &lt;u&gt;The filter that I want to achieve:&lt;/u&gt;
  &lt;br /&gt; find all objects that are of type = '1' AND status = 'in
  progress' &lt;br /&gt; + &lt;br /&gt; find all other objects that are not type =
  '1' without checking the status &lt;/p&gt;
&lt;p&gt;
  &lt;u&gt;My filter should return:&lt;/u&gt;&lt;/p&gt;
&lt;p&gt;[Object1, Object4, Object5]&lt;/p&gt;
&lt;p&gt;I dont know how to achieve this in my postProcessContextBooleanFilter method.&lt;/p&gt;
&lt;p&gt;
  &lt;u&gt;What I have so far:&lt;/u&gt;&lt;/p&gt;
&lt;pre&gt;
&lt;code class="language-java"&gt;TermsFilter typeFilter = new TermsFilter(&amp;quot;type&amp;quot;);
filterDepartmentName.addValues(&amp;quot;1&amp;quot;);

TermsFilter statusFilter = new TermsFilter(&amp;quot;status&amp;quot;);
filterDepartmentName.addValues(&amp;quot;in_progress&amp;quot;);

booleanFilter.add(typeFilter, BooleanClauseOccur.MUST);
booleanFilter.add(statusFilter, BooleanClauseOccur.MUST);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This snippet above will return Object1 from my example. &lt;br /&gt;
  &lt;strong&gt;How do I add another Filter to return Object1 AND all other
    Objects that are not type=1?&lt;/strong&gt;&lt;/p&gt;</summary>
    <dc:creator>Uwe Peters</dc:creator>
    <dc:date>2021-08-10T11:20:52Z</dc:date>
  </entry>
</feed>
