0
curl SOLR_URL/update -d \'
[
 {"id" : "1",
  "ONLINE" : {"set":"1"}
 }
]'

I am using solr6.3. Above command works fine as it update online flag to 1 for id=1. But the issue is if record is not present then it adds a value as id=1 and online=1 which is not desired.

So question is, is it possible that solr updates the value only if record is present in the solr.

Sheldon Cooper
  • 236
  • 4
  • 17

2 Answers2

1

Maybe a little bit late but you could create a required field. If you try to insert a document without this required field the update query fails. Maybe not the most elegant way but at least one solution.

MrSunshine
  • 31
  • 1
  • 7
0

To make sure that a document exists for update, you can simply add the _version_ field with the value 1 to the document. In this case the version is not evaluated but only interpreted that the document must exist.

[
 {"id" : "146546456",
  "ONLINE" : {"set": "1"},
  "_version_" : 1
 }
]

The error message is correspondingly meaningful:

Document not found for update. id=146546456

However, a batch update would never update a document if only one does not exist.