title: Conditional based Elastic Search Query (if else or Union case)
body: <p>I was working on elastic Query (multiple condition/if else based). My problem is as below</p>
  <p>Document 1</p>
  <pre class="lang-json prettyprint-override"><code>{
      &quot;id&quot;: &quot;1234&quot;,
      &quot;isQualified&quot;: true,
      &quot;pending_subjects&quot;: null,
      &quot;student&quot;: {
          &quot;first_name&quot;: &quot;TEST First 1234&quot;,
          &quot;last_name&quot;: &quot;TEST Last 1234&quot;,
          &quot;dob&quot;: &quot;01012005&quot;
      },
      &quot;stud_ext_curr_status&quot; :&quot;A+ve&quot; 
  }
  </code></pre>
  <p>Doc 2</p>
  <pre class="lang-json prettyprint-override"><code>{
      &quot;id&quot;: &quot;12345&quot;,
      &quot;isQualified&quot;: true,
      &quot;pending_subjects&quot;: null,
      &quot;student&quot;: {
          &quot;first_name&quot;: &quot;TEST First 12345&quot;,
          &quot;last_name&quot;: &quot;TEST Last 12345&quot;,
          &quot;dob&quot;: &quot;01022004&quot;
      }
      &quot;stud_ext_curr_status&quot; :&quot;A&quot;
  }
  </code></pre>
  <p>Document 3</p>
  <pre class="lang-json prettyprint-override"><code>{
      &quot;id&quot;: &quot;55676&quot;,
      &quot;isQualified&quot;: true,
      &quot;pending_subjects&quot;: null,
      &quot;student&quot;: {
          &quot;first_name&quot;: &quot;TEST First 565&quot;,
          &quot;last_name&quot;: &quot;TEST Last 12368845&quot;,
          &quot;dob&quot;: &quot;01022004&quot;
      }
      &quot;stud_ext_curr_status&quot; :&quot;C-ve&quot;
  }
  </code></pre>
  <p>Other document</p>
  <pre class="lang-json prettyprint-override"><code>{
      &quot;id&quot;: &quot;1111&quot;,
      &quot;isQualified&quot;: false,
      &quot;pending_subjects&quot;: [
                         &quot;MATH&quot;,
                         &quot;ECONOMICS&quot;
                        ],
      &quot;student&quot;: {
          &quot;first_name&quot;: &quot;TEST First 1111&quot;,
          &quot;last_name&quot;: &quot;TEST Last 1111&quot;,
          &quot;dob&quot;: &quot;02012004&quot;
      }
      &quot;stud_ext_curr_status&quot; :&quot;A+ve&quot;
  }
  </code></pre>
  <p><strong>Doc 4</strong></p>
  <pre class="lang-json prettyprint-override"><code>{
      &quot;id&quot;: &quot;2222&quot;,
      &quot;isQualified&quot;: false,
      &quot;pending_subjects&quot;: [
                         &quot;SCIENCE&quot;
                        ],
      &quot;student&quot;: {
          &quot;first_name&quot;: &quot;TEST First 21&quot;,
          &quot;last_name&quot;: &quot;TEST Last 21&quot;,
          &quot;dob&quot;: &quot;02012004&quot;
      }
      &quot;stud_ext_curr_status&quot; :&quot;A+ve&quot;
  }
  </code></pre>
  <p>So, I would like to have the records (for both <code>isQualified</code> false as well true, but having some specific conditions as below).</p>
  <pre><code>condition 1) if isQualified is false then 
            a)  Filter all records/documents having non null pending_subjects elements
            b)  Filter above case but for the case pending_subjects element having &quot;SCIENCE&quot;         
                 there is need to check stud_ext_curr_status element further to include only if it has &quot;A+ve&quot;
            2) if isQualified is true then filter the document having `stud_ext_curr_status` element value C-ve 
  </code></pre>
  <p>So, basically output should be Union of docs resulting from Condition 1 &amp; 2</p>