title: Elasticsearch check a key exists in an object
body: <p>My partial mapping for one of the indexes:</p>
  
  <pre><code>{
    "title": { "type": "string"},
    "seasons": {
      "type": "object",
      "dynamic": true,
      "properties": {}
    }
  }
  </code></pre>
  
  <p>Currently, I have 4 documents as follows:</p>
  
  <p>Doc 1</p>
  
  <pre><code>{
    "title": "abc",
    "seasons": null
  }
  </code></pre>
  
  <p>Doc 2</p>
  
  <pre><code>{
    "title": "xyz",
    "seasons": {
      "201809": 23,
      "201902": 45
    }
  }
  </code></pre>
  
  <p>Doc 3</p>
  
  <pre><code>{
    "title": "xyz",
    "seasons": {
      "201811": 23,
      "201910": 23,
      "201809": 45,
      "201805": 35,
    }
  }
  </code></pre>
  
  <p>Doc 4</p>
  
  <pre><code>{
    "title": "xyz",
    "seasons": {
      "201802": 23,
      "201902": 45
    }
  }
  </code></pre>
  
  <p><code>seasons</code> object will always be either <code>null</code> or will have <code>key=&gt;val</code> pair.</p>
  
  <p>I want to search all documents which have <code>season</code> field with key <code>201809</code> (here doc2 and doc3 qualify) in it and then do further work on the doc. </p>
  
  <p><strong>REQUIREMENT - I need to run this search using groovy scripting only</strong>. And in my groovy script I do have:</p>
  
  <pre><code>if (doc["seasons.201809"].value) {
     ....more processing after finding the document.....
  }
  </code></pre>
  
  <p>But for this check I get <code>"TransportError(500, 'search_phase_execution_exception', 'no_class_def_found_error: java/lang/Throwable')"</code>. 
  I am sure this line is not the correct check</p>
  
  <pre><code>if (doc["seasons.201809"].value) {
  </code></pre>
  
  <p>Can anyone let me know how to solve this problem of checking a key existence? </p>