json_update.rst 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. .. _http_json_update:
  2. json/update
  3. -----------
  4. This endpoint allows you to update attribute values in documents, same as SphinxQL's :ref:`update_syntax`. Syntax is similar to ``json/insert``, but this time the ``doc`` property is mandatory.
  5. Example:
  6. ::
  7. {
  8. "index":"test",
  9. "id":1,
  10. "doc":
  11. {
  12. "gid" : 100,
  13. "price" : 1000
  14. }
  15. }
  16. The daemon will respond with a JSON object stating if the operation was successfull or not:
  17. ::
  18. {
  19. "_index": "test",
  20. "_id": 1,
  21. "result": "updated"
  22. }
  23. The id of the document that needs to be updated can be set directly using the ``id`` property (as in the example above) or
  24. you can do an update by query and apply the update to all the documents that match the query:
  25. ::
  26. {
  27. "index":"test",
  28. "doc":
  29. {
  30. "price" : 1000
  31. },
  32. "query":
  33. {
  34. "match": { "*": "apple" }
  35. }
  36. }
  37. Query syntax is the same as in the ``json/search`` endpoint. Note that you can't specify ``id`` and ``query`` at the same time.
  38. To update a document in a cluster's index ``cluster`` property should be set along with ``index`` property:
  39. ::
  40. {
  41. "cluster":"nodes4",
  42. "index":"test",
  43. "id":1,
  44. "doc":
  45. {
  46. "gid" : 100,
  47. "price" : 1000
  48. }
  49. }