title: filter empty array fields in elasticsearch
body: <p>My document structure is something like:</p>
  
  <pre><code>{
      title: string,
      description: string,
      privacy_mode: string,
      hidden: boolean,
      added_by: string,
      topics: array
  }
  </code></pre>
  
  <p>I am trying to query elasticsearch. However I dont want any document with empty topics array field.</p>
  
  <p>Below is a function which builds the query object:</p>
  
  <pre><code>function getQueryObject(data) {
      var orList = [{ "term": {"privacy_mode": "public", "hidden": false} }]
      if (data.user) {
          orList.push({ "term": {"added_by": data.user} });
      }
  
      var queryObj = {
          "fields": ["title", "topics", "added_by", "img_url", "url", "type"],
          "query": {
              "filtered" : {
                  "query" : {
                      "multi_match" : {
                          "query" : data.query + '*',
                          "fields" : ["title^4", "topics", "description^3", "tags^2", "body^2", "keywords",
                                  "entities", "_id"]
                      }
                  },
                  "filter" : {
                      "or": orList
                  },
                  "filter" : {
                      "limit" : {"value" : 15}
                  },
                  "filter": {
                     "script": {
                          "script": "doc['topics'].values.length &gt; 0"
                     }
                 }
              }
          }
      }
      return queryObj;
  };
  </code></pre>
  
  <p>This still gives me elements with empty topics array. wondering whats wrong!</p>
  
  <p>Thank for the help </p>