title: Elasticsearch js query with must and must_not
body: <p>I am trying to get a query to run with both must and must_not, but have not had any luck with the syntax I am attempting. I see a lot of people on StackOverflow using quotes on both sides like they would be in a Curl call, but this is straight out of a node application. </p>
  
  <p>I will show the query that does work, and I am simply trying to add what I <strong>do not</strong> want to be included in the outcome. In either case, because this is just trash data that is on a local dev environment, the outcome should match.</p>
  
  <p>First the working query:</p>
  
  <pre><code>client.search({
      index: config.ES_INDEX,
      type: "issue",
      body: {
          query: {
              match: {
                 issue_state: 'Closed'
              }
          },
          size: 1000
      }
  
  }).then(function(resp){
      console.log(util.inspect(resp, {showHidden: false, depth: null}));
  }).catch(function(err){
      console.log('Failed to search. ' + err.message);
  });
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>{ took: 5,
  timed_out: false,
    _shards: { total: 5, successful: 5, failed: 0 },
    hits:
     { total: 1,
       max_score: 1,
       hits:
        [ { _index: 'noc_tool',
            _type: 'issue',
            _id: 'Sy2IQFMLe',
            _score: 1,
            _source:
             { job_name: 'Job Name 1',
               is_maintenance: 'no',
               servicenow_id: 'lkjjklh',
               type: 'Chase',
               start_time: '1970-01-01T23:15:00.000Z',
               maint_reminder: null,
               update_duration: '4 Hours',
               location: 'Test Group',
               issue_state: 'Closed',
               notes: [ { created_on: 1484063571941, body: 'lkjlkjhlkj' } ],
               emailService: { lastEmailAt: 1484237594114 },
               created_on: 1484063571941,
               updated_on: 1484240538801,
               reason: 'because I want to' } } ] } }
  </code></pre>
  
  <p>Now, the failed query:</p>
  
  <pre><code>client.search({
      index: config.ES_INDEX,
      type: "issue",
      body: {
          query: {
              bool: {
                  must: [
                      {
                          term: {
                              issue_state: 'Closed'
                          }
                      }
                  ],
                  must_not: [
                      {
                          term: {
                              is_maintenance: 'yes'
                          }
                      }
                  ]
              }
          },
          size: 1000
      }
  
  }).then(function(resp){
      console.log(util.inspect(resp, {showHidden: false, depth: null}));
  }).catch(function(err){
      console.log('Failed to search. ' + err.message);
  });
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>{ took: 6,
  timed_out: false,
    _shards: { total: 5, successful: 5, failed: 0 },
    hits: { total: 0, max_score: null, hits: [] } }
  </code></pre>
  
  <p>Any help here would be much appreciated.</p>