title: ElasticSearch NEST QueryParsingException bool query does not support filter
body: <p>I'm using NEST 2.3.2 to query ElasticSearch and need to create a conditional filter for FollowUpDateTime field based on optional boolean. If that boolean </p>
  
  <ul>
  <li>is true - want to see all records with non-blank date,  </li>
  <li>is false - records without date,  </li>
  <li>is null - show all records.</li>
  </ul>
  
  <p>Here's what I have in Nest:             </p>
  
  <pre><code>                    var containers = new QueryContainer[7];
                      //Size is based on hte number of search parameters.. 
                      var descriptor = new QueryContainerDescriptor&lt;EsNoteModel&gt;();
  
                      var filters = new QueryContainer[1];
                      var filterdescriptor = new QueryContainerDescriptor&lt;EsNoteModel&gt;();  
  
         /*...... some code for other parameters here .....*/
  
          if (hasFollowUpDate.HasValue)
                      {
                          if ((bool) hasFollowUpDate)
                          {
                              //If true shows only with a non-blank follow-up date
                              filters[0] = filterdescriptor.Exists(ff =&gt; ff.Field("FollowUpDateTime"));
                          }
                          else
                          {
                              //If false shows only notes with a blank follow-up date
                              filters[0] = filterdescriptor.Missing(ff =&gt; ff.Field("FollowUpDateTime"));
                          }
                      }
  
  /*...... CALL to ES below .....*/    
  
                      var result = ElasticSearchClient.Search&lt;EsNoteModel&gt;(body =&gt; body
                          .From(offset - 1)
                          .Size(rows)
                          .Query(q =&gt; q
                              .Bool(b =&gt; b
                                    .Must(containers)
                                    .Filter(f =&gt; f.Bool(t =&gt; t.Must(filters)))
                                    )
                                  )
  
                          .Sort(s =&gt; s
                              .Field(f =&gt; f
                                  .Field(p =&gt; p.NoteDate)
                                  .Order(SortOrder.Descending)))
  
                          );
  </code></pre>
  
  <p>The problem is that the query above generated the error. Please see below:</p>
  
  <blockquote>
    <p>Invalid NEST response built from a unsuccessful low level call on
    POST: /_search?pretty=true</p>
    
    <h1>Audit trail of this API call:</h1>
    
    <ul>
    <li>BadResponse: Node: http://**********.es.amazonaws.com/ Took: 00:00:00.1381301
    
    <h1>OriginalException: System.Net.WebException: The remote server returned an error: (400) Bad Request.    at</h1></li>
    </ul>
    
    <p>System.Net.HttpWebRequest.GetResponse()    at
    Elasticsearch.Net.HttpConnection.Request[TReturn](RequestData
    requestData)</p>
  </blockquote>
  
  <pre><code># Request:
  {
    "from": 0,
    "size": 25,
    "sort": [
      {
        "NoteDate": {
          "order": "desc"
        }
      }
    ],
    "query": {
      "bool": {
        "must": [
          {
            "match": {
              "CustomerId": {
                "query": "2810855"
              }
            }
          }
        ],
        "filter": [
          {
            "bool": {
              "must": [
                {
                  "exists": {
                    "field": "FollowUpDateTime"
                  }
                }
              ]
            }
          }
        ]
      }
    }
  }
  </code></pre>
  
  <p>Response below:</p>
  
  <pre><code># Response:
  {
    "error" : "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[-t7SwBo_TjeH_98h_56ANw][customernote][0]: RemoteTransportException[[Neophyte][inet[/x.x.x.x:y]][indices:data/read/search[phase/query]]]; nested: SearchParseException[[customernote][0]: from[0],size[25],sort[&lt;custom:\"NoteDate\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@2d55231&gt;!]: Parse Failure [Failed to parse source [{\r\n  \"from\": 0,\r\n  \"size\": 25,\r\n  \"sort\": [\r\n    {\r\n      \"NoteDate\": {\r\n        \"order\": \"desc\"\r\n      }\r\n    }\r\n  ],\r\n  \"query\": {\r\n    \"bool\": {\r\n      \"must\": [\r\n        {\r\n          \"match\": {\r\n            \"CustomerId\": {\r\n              \"query\": \"28_10855\"\r\n            }\r\n          }\r\n        }\r\n      ],\r\n      \"filter\": [\r\n        {\r\n          \"bool\": {\r\n            \"must\": [\r\n              {\r\n                \"exists\": {\r\n                  \"field\": \"FollowUpDateTime\"\r\n                }\r\n              }\r\n            ]\r\n          }\r\n        }\r\n      ]\r\n    }\r\n  }\r\n}]]]; nested: QueryParsingException[[customernote] bool query does not support [filter]]; }{[TOOugCq3ROqF9CGnHIay2g][customernote][1]: SearchParseException[[customernote][1]: from[0],size[25],sort[&lt;custom:\"NoteDate\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@562f97b5&gt;!]: Parse Failure [Failed to parse source [{\r\n  \"from\": 0,\r\n  \"size\": 25,\r\n  \"sort\": [\r\n    {\r\n      \"NoteDate\": {\r\n        \"order\": \"desc\"\r\n      }\r\n    }\r\n  ],\r\n  \"query\": {\r\n    \"bool\": {\r\n      \"must\": [\r\n        {\r\n          \"match\": {\r\n            \"CustomerId\": {\r\n              \"query\": \"28_10855\"\r\n            }\r\n          }\r\n        }\r\n      ],\r\n      \"filter\": [\r\n        {\r\n          \"bool\": {\r\n            \"must\": [\r\n              {\r\n                \"exists\": {\r\n                  \"field\": \"FollowUpDateTime\"\r\n                }\r\n              }\r\n            ]\r\n          }\r\n        }\r\n      ]\r\n    }\r\n  }\r\n}]]]; nested: QueryParsingException[[customernote] bool query does not support [filter]]; }{[TOOugCq3ROqF9CGnHIay2g][customernote][2]: SearchParseException[[customernote][2]: from[0],size[25],sort[&lt;custom:\"NoteDate\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@394cf46e&gt;!]: Parse Failure [Failed to parse source [{\r\n  \"from\": 0,\r\n  \"size\": 25,\r\n  \"sort\": [\r\n    {\r\n      \"NoteDate\": {\r\n        \"order\": \"desc\"\r\n      }\r\n    }\r\n  ],\r\n  \"query\": {\r\n    \"bool\": {\r\n      \"must\": [\r\n        {\r\n          \"match\": {\r\n            \"CustomerId\": {\r\n              \"query\": \"28_10855\"\r\n            }\r\n          }\r\n        }\r\n      ],\r\n      \"filter\": [\r\n        {\r\n          \"bool\": {\r\n            \"must\": [\r\n              {\r\n                \"exists\": {\r\n                  \"field\": \"FollowUpDateTime\"\r\n                }\r\n              }\r\n            ]\r\n          }\r\n        }\r\n      ]\r\n    }\r\n  }\r\n}]]]; nested: QueryParsingException[[customernote] bool query does not support [filter]]; }{[-t7SwBo_TjeH_98h_56ANw][customernote][3]: RemoteTransportException[[Neophyte][inet[/x.x.x.x:y]][indices:data/read/search[phase/query]]]; nested: SearchParseException[[customernote][3]: from[0],size[25],sort[&lt;custom:\"NoteDate\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@46d07ba8&gt;!]: Parse Failure [Failed to parse source [{\r\n  \"from\": 0,\r\n  \"size\": 25,\r\n  \"sort\": [\r\n    {\r\n      \"NoteDate\": {\r\n        \"order\": \"desc\"\r\n      }\r\n    }\r\n  ],\r\n  \"query\": {\r\n    \"bool\": {\r\n      \"must\": [\r\n        {\r\n          \"match\": {\r\n            \"CustomerId\": {\r\n              \"query\": \"28_10855\"\r\n            }\r\n          }\r\n        }\r\n      ],\r\n      \"filter\": [\r\n        {\r\n          \"bool\": {\r\n            \"must\": [\r\n              {\r\n                \"exists\": {\r\n                  \"field\": \"FollowUpDateTime\"\r\n                }\r\n              }\r\n            ]\r\n          }\r\n        }\r\n      ]\r\n    }\r\n  }\r\n}]]]; nested: QueryParsingException[[customernote] bool query does not support [filter]]; }{[TOOugCq3ROqF9CGnHIay2g][customernote][4]: SearchParseException[[customernote][4]: from[0],size[25],sort[&lt;custom:\"NoteDate\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@74fb3710&gt;!]: Parse Failure [Failed to parse source [{\r\n  \"from\": 0,\r\n  \"size\": 25,\r\n  \"sort\": [\r\n    {\r\n      \"NoteDate\": {\r\n        \"order\": \"desc\"\r\n      }\r\n    }\r\n  ],\r\n  \"query\": {\r\n    \"bool\": {\r\n      \"must\": [\r\n        {\r\n          \"match\": {\r\n            \"CustomerId\": {\r\n              \"query\": \"28_10855\"\r\n            }\r\n          }\r\n        }\r\n      ],\r\n      \"filter\": [\r\n        {\r\n          \"bool\": {\r\n            \"must\": [\r\n              {\r\n                \"exists\": {\r\n                  \"field\": \"FollowUpDateTime\"\r\n                }\r\n              }\r\n            ]\r\n          }\r\n        }\r\n      ]\r\n    }\r\n  }\r\n}]]]; nested: QueryParsingException[[customernote] bool query does not support [filter]]; }]",
    "status" : 400
  }
  </code></pre>
  
  <p>As you see error reports "nested: QueryParsingException[[customernote] bool query does not support [filter]];" Any ideas what I'm doing wrong in this example? Is this a proper use of filter clause?</p>
  
  <p>**** UPDATE</p>
  
  <p>changed query </p>
  
  <pre><code> var result = ElasticSearchClient.Search&lt;EsNoteModel&gt;(body =&gt; body
                  .From(offset - 1)
                  .Size(rows)
                  .Query(q =&gt; q
                      .Bool(b =&gt; b
                            .Must(containers)
                            .Filter(filters)
                            )
                          )
  
                  .Sort(s =&gt; s
                      .Field(f =&gt; f
                          .Field(p =&gt; p.NoteDate)
                          .Order(SortOrder.Descending)))
  
                  );
  </code></pre>
  
  <p>request to </p>
  
  <pre><code># Request:
  {
    "from": 0,
    "size": 25,
    "sort": [
      {
        "NoteDate": {
          "order": "desc"
        }
      }
    ],
    "query": {
      "bool": {
        "must": [
          {
            "match": {
              "CustomerId": {
                "query": "2810855"
              }
            }
          }
        ],
        "filter": [
          {
            "exists": {
              "field": "FollowUpDateTime"
            }
          }
        ]
      }
    }
  }
  </code></pre>
  
  <p>getting response error:</p>
  
  <pre><code># Response:
  {
    "error" : "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[TOOugCq3ROqF9CGnHIay2g][customernote][0]: SearchParseException[[customernote][0]: from[0],size[25],sort[&lt;custom:\"NoteDate\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@4839a60c&gt;!]: Parse Failure [Failed to parse source [{\r\n  \"from\": 0,\r\n  \"size\": 25,\r\n  \"sort\": [\r\n    {\r\n      \"NoteDate\": {\r\n        \"order\": \"desc\"\r\n      }\r\n    }\r\n  ],\r\n  \"query\": {\r\n    \"bool\": {\r\n      \"must\": [\r\n        {\r\n          \"match\": {\r\n            \"CustomerId\": {\r\n              \"query\": \"2810855\"\r\n            }\r\n          }\r\n        }\r\n      ],\r\n      \"filter\": [\r\n        {\r\n          \"exists\": {\r\n            \"field\": \"FollowUpDateTime\"\r\n          }\r\n        }\r\n      ]\r\n    }\r\n  }\r\n}]]]; nested: QueryParsingException[[customernote] bool query does not support [filter]]; }{[-t7SwBo_TjeH_98h_56ANw][customernote][1]: RemoteTransportException[[Neophyte][inet[/x.x.x.x:y]][indices:data/read/search[phase/query]]]; nested: SearchParseException[[customernote][1]: from[0],size[25],sort[&lt;custom:\"NoteDate\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@21d845ae&gt;!]: Parse Failure [Failed to parse source [{\r\n  \"from\": 0,\r\n  \"size\": 25,\r\n  \"sort\": [\r\n    {\r\n      \"NoteDate\": {\r\n        \"order\": \"desc\"\r\n      }\r\n    }\r\n  ],\r\n  \"query\": {\r\n    \"bool\": {\r\n      \"must\": [\r\n        {\r\n          \"match\": {\r\n            \"CustomerId\": {\r\n              \"query\": \"2810855\"\r\n            }\r\n          }\r\n        }\r\n      ],\r\n      \"filter\": [\r\n        {\r\n          \"exists\": {\r\n            \"field\": \"FollowUpDateTime\"\r\n          }\r\n        }\r\n      ]\r\n    }\r\n  }\r\n}]]]; nested: QueryParsingException[[customernote] bool query does not support [filter]]; }{[-t7SwBo_TjeH_98h_56ANw][customernote][2]: RemoteTransportException[[Neophyte][inet[/x.x.x.x:y]][indices:data/read/search[phase/query]]]; nested: SearchParseException[[customernote][2]: from[0],size[25],sort[&lt;custom:\"NoteDate\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@6124d214&gt;!]: Parse Failure [Failed to parse source [{\r\n  \"from\": 0,\r\n  \"size\": 25,\r\n  \"sort\": [\r\n    {\r\n      \"NoteDate\": {\r\n        \"order\": \"desc\"\r\n      }\r\n    }\r\n  ],\r\n  \"query\": {\r\n    \"bool\": {\r\n      \"must\": [\r\n        {\r\n          \"match\": {\r\n            \"CustomerId\": {\r\n              \"query\": \"2810855\"\r\n            }\r\n          }\r\n        }\r\n      ],\r\n      \"filter\": [\r\n        {\r\n          \"exists\": {\r\n            \"field\": \"FollowUpDateTime\"\r\n          }\r\n        }\r\n      ]\r\n    }\r\n  }\r\n}]]]; nested: QueryParsingException[[customernote] bool query does not support [filter]]; }{[TOOugCq3ROqF9CGnHIay2g][customernote][3]: SearchParseException[[customernote][3]: from[0],size[25],sort[&lt;custom:\"NoteDate\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@f884425&gt;!]: Parse Failure [Failed to parse source [{\r\n  \"from\": 0,\r\n  \"size\": 25,\r\n  \"sort\": [\r\n    {\r\n      \"NoteDate\": {\r\n        \"order\": \"desc\"\r\n      }\r\n    }\r\n  ],\r\n  \"query\": {\r\n    \"bool\": {\r\n      \"must\": [\r\n        {\r\n          \"match\": {\r\n            \"CustomerId\": {\r\n              \"query\": \"2810855\"\r\n            }\r\n          }\r\n        }\r\n      ],\r\n      \"filter\": [\r\n        {\r\n          \"exists\": {\r\n            \"field\": \"FollowUpDateTime\"\r\n          }\r\n        }\r\n      ]\r\n    }\r\n  }\r\n}]]]; nested: QueryParsingException[[customernote] bool query does not support [filter]]; }{[-t7SwBo_TjeH_98h_56ANw][customernote][4]: RemoteTransportException[[Neophyte][inet[/x.x.x.x:y]][indices:data/read/search[phase/query]]]; nested: SearchParseException[[customernote][4]: from[0],size[25],sort[&lt;custom:\"NoteDate\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@77228f64&gt;!]: Parse Failure [Failed to parse source [{\r\n  \"from\": 0,\r\n  \"size\": 25,\r\n  \"sort\": [\r\n    {\r\n      \"NoteDate\": {\r\n        \"order\": \"desc\"\r\n      }\r\n    }\r\n  ],\r\n  \"query\": {\r\n    \"bool\": {\r\n      \"must\": [\r\n        {\r\n          \"match\": {\r\n            \"CustomerId\": {\r\n              \"query\": \"2810855\"\r\n            }\r\n          }\r\n        }\r\n      ],\r\n      \"filter\": [\r\n        {\r\n          \"exists\": {\r\n            \"field\": \"FollowUpDateTime\"\r\n          }\r\n        }\r\n      ]\r\n    }\r\n  }\r\n}]]]; nested: QueryParsingException[[customernote] bool query does not support [filter]]; }]",
    "status" : 400
  }
  </code></pre>
  
  <p>Basically same error</p>
  
  <p>nested: QueryParsingException[[customernote] bool query does not support [filter]];</p>