<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to upsert to the KV Store via REST API? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-upsert-to-the-KV-Store-via-REST-API/m-p/238884#M46399</link>
    <description>&lt;P&gt;&lt;A href="http://dev.splunk.com/view/SP-CAAAEY7"&gt;http://dev.splunk.com/view/SP-CAAAEY7&lt;/A&gt; states that the KV store allows "upserts", but doesn't elaborate on how to perform them. Does this mean that I can perform an operation that inserts a document into the collection, or updates it if it already exists? How can I do this?&lt;/P&gt;

&lt;P&gt;In my tests, POSTing a document with a duplicate _key to &lt;CODE&gt;storage/collections/data/{collection}&lt;/CODE&gt; causes an error, and POSTing an update to &lt;CODE&gt;storage/collections/data/{collection}/{id}&lt;/CODE&gt; where &lt;CODE&gt;id&lt;/CODE&gt; doesn't exist also returns an error. Is there a single operation that's equivalent to SQL's &lt;CODE&gt;INSERT ... ON DUPLICATE KEY UPDATE&lt;/CODE&gt;?&lt;/P&gt;</description>
    <pubDate>Tue, 19 Jan 2016 22:09:58 GMT</pubDate>
    <dc:creator>sjodle</dc:creator>
    <dc:date>2016-01-19T22:09:58Z</dc:date>
    <item>
      <title>How to upsert to the KV Store via REST API?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-upsert-to-the-KV-Store-via-REST-API/m-p/238884#M46399</link>
      <description>&lt;P&gt;&lt;A href="http://dev.splunk.com/view/SP-CAAAEY7"&gt;http://dev.splunk.com/view/SP-CAAAEY7&lt;/A&gt; states that the KV store allows "upserts", but doesn't elaborate on how to perform them. Does this mean that I can perform an operation that inserts a document into the collection, or updates it if it already exists? How can I do this?&lt;/P&gt;

&lt;P&gt;In my tests, POSTing a document with a duplicate _key to &lt;CODE&gt;storage/collections/data/{collection}&lt;/CODE&gt; causes an error, and POSTing an update to &lt;CODE&gt;storage/collections/data/{collection}/{id}&lt;/CODE&gt; where &lt;CODE&gt;id&lt;/CODE&gt; doesn't exist also returns an error. Is there a single operation that's equivalent to SQL's &lt;CODE&gt;INSERT ... ON DUPLICATE KEY UPDATE&lt;/CODE&gt;?&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 22:09:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-upsert-to-the-KV-Store-via-REST-API/m-p/238884#M46399</guid>
      <dc:creator>sjodle</dc:creator>
      <dc:date>2016-01-19T22:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to upsert to the KV Store via REST API?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-upsert-to-the-KV-Store-via-REST-API/m-p/238885#M46400</link>
      <description>&lt;P&gt;Hi @sjodle,&lt;/P&gt;

&lt;P&gt;You can create a new item by POSTing to the collection. This POST allocates the /{id} resource that you can then use for updating that item, using a POST to the /{id} endpoint. &lt;/P&gt;

&lt;P&gt;In case it helps, having the "upsert" functionality might allow for mistakes where a user means to indicate an existing id but makes a POST using an incorrect id that happens to be non-allocated. If a new resource is created for the incorrect and non-allocated id, then the update can't be made to the correct id and the user might not find out.&lt;/P&gt;

&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jan 2016 22:57:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-upsert-to-the-KV-Store-via-REST-API/m-p/238885#M46400</guid>
      <dc:creator>frobinson_splun</dc:creator>
      <dc:date>2016-01-19T22:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to upsert to the KV Store via REST API?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-upsert-to-the-KV-Store-via-REST-API/m-p/238886#M46401</link>
      <description>&lt;P&gt;Hi sjodle,&lt;/P&gt;

&lt;P&gt;This may not be what you are looking for, but an alternative option would be to use &lt;CODE&gt;lookup/outputlookup&lt;/CODE&gt;  command.&lt;BR /&gt;
Below query would do the upserts into kvstore&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Base Search | lookup &amp;lt;lookup_name&amp;gt; &amp;lt;lookup_field&amp;gt; OUTPUTNEW _key AS _key | outputlookup &amp;lt;lookup_name&amp;gt; append=true
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Jan 2016 23:48:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-upsert-to-the-KV-Store-via-REST-API/m-p/238886#M46401</guid>
      <dc:creator>Murali2888</dc:creator>
      <dc:date>2016-01-19T23:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to upsert to the KV Store via REST API?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-upsert-to-the-KV-Store-via-REST-API/m-p/238887#M46402</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;In case it helps, having the "upsert" functionality might allow for mistakes where a user means to indicate an existing id but makes a POST using an incorrect id that happens to be non-allocated. If a new resource is created for the incorrect and non-allocated id, then the update can't be made to the correct id and the user might not find out.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;MongoDB (which the KV Store is built upon) mitigates this problem by requiring an "upsert: true" parameter to be explicitly passed, otherwise an error is returned. This ensures that the user understands the potential risks associated with upserts, and ensures that they don't happen by default without the user's knowledge.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 18:29:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-upsert-to-the-KV-Store-via-REST-API/m-p/238887#M46402</guid>
      <dc:creator>sjodle</dc:creator>
      <dc:date>2016-01-20T18:29:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to upsert to the KV Store via REST API?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-upsert-to-the-KV-Store-via-REST-API/m-p/238888#M46403</link>
      <description>&lt;P&gt;Thanks for the answer. I'll mark it as answered and proceed with my plan B: try an insert, except if it fails due to duplicate key, retry it as an update. Upserts would be an excellent feature addition in future versions, though!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 18:33:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-upsert-to-the-KV-Store-via-REST-API/m-p/238888#M46403</guid>
      <dc:creator>sjodle</dc:creator>
      <dc:date>2016-01-20T18:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to upsert to the KV Store via REST API?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-upsert-to-the-KV-Store-via-REST-API/m-p/238889#M46404</link>
      <description>&lt;P&gt;Thanks for your suggestions, @sjodle! I've passed them along to the engineering team.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 18:54:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-upsert-to-the-KV-Store-via-REST-API/m-p/238889#M46404</guid>
      <dc:creator>frobinson_splun</dc:creator>
      <dc:date>2016-01-20T18:54:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to upsert to the KV Store via REST API?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-upsert-to-the-KV-Store-via-REST-API/m-p/238890#M46405</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/134340"&gt;@sjodle&lt;/a&gt;, this can be done using batch_save endpoint &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.3.2/RESTREF/RESTkvstore#storage.2Fcollections.2Fdata.2F.7Bcollection.7D.2Fbatch_save" target="_blank"&gt;http://docs.splunk.com/Documentation/Splunk/6.3.2/RESTREF/RESTkvstore#storage.2Fcollections.2Fdata.2F.7Bcollection.7D.2Fbatch_save&lt;/A&gt; &lt;/P&gt;

&lt;P&gt;You can find few examples on this page as well &lt;A href="http://dev.splunk.com/view/webframework-developapps/SP-CAAAEZG" target="_blank"&gt;http://dev.splunk.com/view/webframework-developapps/SP-CAAAEZG&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;As suggested by &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/115917"&gt;@Murali2888&lt;/a&gt; - batch_save is very similar to SPL command &lt;CODE&gt;outputlookup append=true&lt;/CODE&gt;, it inserts all new documents and replaces all documents which already exist in collection.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 08:29:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-upsert-to-the-KV-Store-via-REST-API/m-p/238890#M46405</guid>
      <dc:creator>dgladkikh_splun</dc:creator>
      <dc:date>2020-09-29T08:29:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to upsert to the KV Store via REST API?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-upsert-to-the-KV-Store-via-REST-API/m-p/238891#M46406</link>
      <description>&lt;P&gt;Thanks! I'll check that out!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2016 21:29:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-upsert-to-the-KV-Store-via-REST-API/m-p/238891#M46406</guid>
      <dc:creator>sjodle</dc:creator>
      <dc:date>2016-01-20T21:29:49Z</dc:date>
    </item>
  </channel>
</rss>

