title: Upsert function for elasicsearch?
body: <p>I would like to periodically update the data in elasticsearch.</p>
  
  <p>In the file I send in for update, there may be data that already exist in elasticsearh (for update) and data that are new docs (for insert).</p>
  
  <p>Since the data in elasticsearch is managed by auto-created ID,
  I have to search the ID by a column "code"(unique) to make sure if a doc already exists, if exists update, otherwise insert. </p>
  
  <p>I wonder if there is any method that is faster than the codes I think of as below.</p>
  
  <pre><code>es = Elasticsearch()
  
  # get doc ID by searching(exact match) a code to check if ID exists
  res = es.search(index=index_name, doc_type=doc_type, body=body_for_search)
  id_dict = dict([('id', doc['_id'])]) for doc in res['hits']['hits’]
  
  # if id exists, update the current doc by id   
  # else insert with auto-created id 
  If id_dict['id']:
      es.update(index=index_name, id=id_dict['id'], doc_type=doc_type, body=body)
  else:
      es.index(index=index_name, doc_type=doc_type, body=body)
  </code></pre>
  
  <p>For example, could there be a method where elasticsearch search the exact match <code>col["code"]</code> for you and you can simply "upsert" the data without specifying id?
  Any advice would be much appreciated and thank you for your reading.</p>
  
  <p>ps- if we make the <code>id = col["code"]</code> it could be much simpler and faster,  but for management issue we can't do it at current stage.</p>