title: Check for a specific text in entire elastic search document as string
body: <p>I am working on a use-case, wherein I want to identify which document in elastic search has a particular keyword in any of the field values (indexed as well as non-indexed).
  In the case of SQL, this will be straightforward, though it will be a bit heavy. Like for Postgres, we can do:</p>
  <pre><code>select count(1) from table where data::text like '%keyword%'
  </code></pre>
  <p>But, in the case of elastic search, I am experimenting with the painless script.
  Here is what I am trying:</p>
  <ul>
  <li>Use script filter</li>
  <li>Add painless script to convert entire document JSON to a string</li>
  <li>And, in the script, return true if the document string contains the keyword</li>
  </ul>
  <p>Now, I tried different variations of following in the <code>scripted_field</code> clause to convert the entire document to string:</p>
  <pre><code> - doc.toString()
   - doc['_source'].value
   - params._source.toString()
   - ctx._source.value.toString()
  </code></pre>
  <p>And, none worked.</p>
  <p>However, I could see that retrieving individual field values is working.
  So, following query gives the below mentioned result:</p>
  <pre><code>&quot;script_fields&quot;: {
      &quot;myfield&quot;: {
        &quot;script&quot;: &quot;&quot;&quot;
              return params._source.id.toString();
        &quot;&quot;&quot;
      }
  }
  </code></pre>
  <p>Result:</p>
  <pre><code>{
    &quot;_index&quot;: &quot;myindex&quot;,
    &quot;_type&quot;: &quot;mytype&quot;,
    &quot;_id&quot;: &quot;1557e321-b6be-491f-a869-9309194af658&quot;,
    &quot;_score&quot;: 13.808922,
    &quot;myfield&quot;: {
      &quot;text&quot;: [
        &quot;1557e321-b6be-491f-a869-9309194af658&quot;
      ]
    }
  }
  </code></pre>
  <p>Can anyone help in converting entire document json to string at runtime in ES?</p>