title: How to use bodybuilder to generate a dynamic query from frontend?
body: <p>I'm using <a href="http://bodybuilder.js.org/" rel="nofollow noreferrer">bodybuilder</a> to generate the elasticsearch query but I don't know how to create a complex query with query, filter and all.</p>
  
  <p>Suppose I have fields in an array</p>
  
  <pre><code>let queryArr =
  [
    {
      type: 'query',
      field: 'message',
      input: 'this is a test'    
    },
    {
      type: 'filter',
      field: 'user',
      input: 'sample'    
    },
    {
      type: 'notfilter',
      field: 'user',
      input: 'demo'    
    },
    {
      type: 'query',
      field: 'name',
      input: 'test'    
    }
  ]
  </code></pre>
  
  <p>How can I generate the below final query structure to be passed to bodybuilder from this array ?</p>
  
  <pre><code>let finalQuery = bodybuilder()
          .query('match', 'message', 'this is a test')
          .filter('term', 'user', 'sample')
          .notFilter('term', 'user', 'demo')
          .query('match', 'name', 'test')
          .build()
  </code></pre>
  
  <p>Here bodybuilder and build are functions provided by bodybuilder.</p>
  
  <p>I tried using template strings but it didn't work.</p>
  
  <p><strong>I'm open to suggestions for any other client side JS querybuilder which takes array as input and returns an elasticsearch query.</strong></p>