Using ElasticSearch Bulk to update and create documents dynamically?
<p>I'm currently using <code>elasticsearch</code> and running a cron job every 10 minutes that will find newly created/updated data from my DB and sync it with <code>elasticsearch</code>. However, I want to use <code>bulk</code> to sync instead of making and arbitrary amount of requests to update/create documents in an index. I'm using the elasticsearch.js library created by elasticsearch.</p>

<p>I face 2 challenges that I'm uncertain about how to handle:</p>

<ul>
<li>How to use <code>bulk</code> to update a document if it exists and create a document if it doesn't within <code>bulk</code> without knowing if it exists in the index.</li>
<li>How to format a large amount of <code>JSON</code> to run through <code>bulk</code> to update/create the document because <code>bulk</code> api expects the body to be formatted a certain way.</li>
</ul>