On 9/17/2015 9:48 AM, Alfonso Muñoz-Pomer Fuentes wrote: > Hi, I have a question regarding atomic updates on multiple documents. > > We’re using Solr 5.1.0, and I’m wondering if it’s possible to perform > an atomic update on multiple documents with one request. > > After having a look at http://yonik.com/solr/atomic-updates/ I tried > to do the following after the example by Yonik: > $ curl http://localhost:8983/solr/demo/update -d ' > [ > {"author_s" : "Neal Stephenson", > "cat_ss" : {"add":"Cyberpunk"} > } > ]' > > I expected it would add the category “Cyberpunk” to all the books by > “Neal Stephenson”, but instead a new document with only those fields > was created. > > Is there a way to achieve what I described above, without reading all > the relevant documents, modify them, and then sending them back to Solr?
I think you're probably looking at Yonik's example that looks like this: |$ curl http:||//localhost:8983/solr/demo/update -d '| |[| | ||{||"id"| |: ||"book1"||,| | ||"author_s"| |: {||"set"||:||"Neal Stephenson"||},| | ||"copies_i"| |: {||"inc"||:3},| | ||"cat_ss"| |: {||"add"||:||"Cyberpunk"||}| | ||}| |]' What this means in practical terms is this: * Find the existing document with the id of "book1". * Set (replace if already present) the author. * Increment the number of copies by three. * Add Cyberpunk to the category list. | This assumes that the uniqueKey field is "id". Unless your uniqueKey field is "author_s" (which is highly unlikely), the JSON that you used will not work. Chances are that the request failed, that nothing happened. Notice that the document (surrounded by curly braces) is inside square brackets. This is standard JSON syntax. The curly braces mark a data structure like a Java "Map" object, and the square brackets indicate an array. You can put multiple documents in the array, in accordance with JSON syntax. You will need to know all the ID values that you want to update, and construct a document for each of them ... Solr does not have anything like the SQL syntax that lets you update all rows that match a WHERE clause. Thanks, Shawn