title: Elastic v.7 - Painless script to filter by non indexed field
body: <p>In some elastic documents, a field has been added that is not indexed in the mapping. I'm trying to filter for documents that don't have this field like this:</p>
  <pre><code>GET {index}/_search
  {
      &quot;query&quot;: {
          &quot;bool&quot; : {
              &quot;filter&quot; : {
                  &quot;script&quot; : {
                      &quot;script&quot; : {
                          &quot;source&quot;: &quot;&quot;&quot;
                            doc['published'].value == 'xxx'
                           &quot;&quot;&quot;,
                          &quot;lang&quot;: &quot;painless&quot;
                       }
                  }
              }
          }
      }
  }
  </code></pre>
  <p>Also tried with <code>doc.containsKey('published')</code> inside souce;</p>
  <p>However, as the field 'published' is not in the index mapping, I'm having the error:</p>
  <p>&quot;No field found for [published] in mapping with types []&quot;</p>
  <p>Is there a way to search/filter with this non-indexed field?</p>
  <p>Here I found someone who did: <a href="https://discuss.elastic.co/t/how-to-search-non-indexed-field-in-elasticsearch/20594/4" rel="nofollow noreferrer">https://discuss.elastic.co/t/how-to-search-non-indexed-field-in-elasticsearch/20594/4</a> . But that's an older elastic version and that query didn't work after adapting to the version 7.</p>