title: Nest Elastic - Building Dynamic Nested Query
body: <p>I have to query a nested object using Nest, however the query is built in dynamic way. Below is code that demonstrate using query on nested &quot;books&quot; in a static way</p>
  <pre class="lang-cs prettyprint-override"><code>QueryContainer qry;
  qry = new QueryStringQuery()
  {
      DefaultField = &quot;name&quot;,
      DefaultOperator = Operator.And,
      Query = &quot;salman&quot;
  };
  
  QueryContainer qry1 = null;
  
  qry1 = new RangeQuery() // used to search for range ( from , to)
  {
      Field = &quot;modified&quot;,
      GreaterThanOrEqualTo = Convert.ToDateTime(&quot;21/12/2015&quot;).ToString(&quot;dd/MM/yyyy&quot;),
  };
  
  QueryContainer all = qry &amp;&amp; qry1;
  
  var results = elastic.Search&lt;Document&gt;(s =&gt; s
     .Query(q =&gt; q
          .Bool(qb =&gt; qb
              .Must(all)))
      .Filter(f =&gt;
              f.Nested(n =&gt; n
                   .Path(&quot;books&quot;)
                      .Filter(f3 =&gt; f3.And(
                                  f1 =&gt; f1.Term(&quot;book.isbn&quot;, &quot;122&quot;),
                                  f2 =&gt; f2.Term(&quot;book.author&quot;, &quot;X&quot;))
  
                              )
                      )
              )
  
      );
  </code></pre>
  <p>The problem is that i need to combine multiple queries (using And,OR operators) for &quot;books&quot; in dynamic fashion. For example, get the books that satisfy these set of conditions:</p>
  <ol>
  <li>Condition 1: Books that has Author &quot;X&quot; and isbn &quot;1&quot;</li>
  <li>Condition 2: Books that has Author &quot;X&quot; and isbn &quot;2&quot;</li>
  <li>Condition 3: Books that has Author &quot;Z&quot; and isbn &quot;3&quot;</li>
  <li>Other Condtions: .....</li>
  </ol>
  <p>Now, the filter in the nested Query should retrieve books if:<br />
  Condition 1 <strong>AND</strong> Condition 2 <strong>Or</strong> Condition 3</p>
  <p>Suppose that i have class name FilterOptions that contains the following attributes:</p>
  <ol>
  <li>FieldName</li>
  <li>Value</li>
  <li>Operator (which will combine the next filter)</li>
  </ol>
  <p>I am going to loop on the given FilterOptions array to build the query.</p>
  <blockquote>
  <p>Question:</p>
  </blockquote>
  <p>What should i use to build the nested query? Is it a FilterDesciptor and how to combine them add the nested query to the Search Method?</p>
  <p>Please, recommend any valuable link or example?</p>