title: How to get a particular document with the given ID exist or not in elasticsearch using groovy script
body: <p>I am using a groovy script to append data to an array as follows</p>
  
  <pre><code>body = {
          "script": {
              "lang": "groovy",
              "file": "demo_script",
              "params": {
                  "users": array_ids
                  }
              }
          }
  es.update(index="demo_index", doc_type = "demo_type", id = uid, body = body)
  </code></pre>
  
  <p>My script is as follows,</p>
  
  <pre><code>if (!ctx._source.user_ids.contains(users)){ctx._source.user_ids += users}
  </code></pre>
  
  <p>In the groovy script, before I am appending the array elements (Here array_ids is the list of ids to be appended), I need to check whether a document exists in the ES with the given ID, In my case uid.
  How can I do that in groovy scripting</p>