json_insert.rst 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. .. _http_json_insert:
  2. json/insert
  3. -----------
  4. Documents can be inserted into RT indexes using the ``/json/insert`` endpoint. As with SphinxQL's :ref:`insert_and_replace_syntax`, documents with ids that already exist will not be overwritten. You can also use the ``/json/create`` endpoint, it's a synonym for ``json/insert``.
  5. Here's how you can index a simple document:
  6. ::
  7. {
  8. "index":"test",
  9. "id":1
  10. }
  11. This creates a document with an id specified by ``id`` in an index specified by the ``index`` property. This document has empty fulltext fields and all attributes are set to their default values. However, you can use the optional ``doc`` property to set field and attribute values:
  12. ::
  13. {
  14. "index":"test",
  15. "id":1,
  16. "doc":
  17. {
  18. "gid" : 10,
  19. "content" : "new document"
  20. }
  21. }
  22. The daemon will respond with a JSON object stating if the operation was successfull or not:
  23. ::
  24. {
  25. "_index": "test",
  26. "_id": 1,
  27. "created": true,
  28. "result": "created"
  29. }
  30. MVA attributes are inserted as arrays of numbers. JSON attributes can be inserted either as JSON objects or as strings containing escaped JSON:
  31. ::
  32. {
  33. "index":"test",
  34. "id":1,
  35. "doc":
  36. {
  37. "mva" : [1,2,3,4,5],
  38. "json1":
  39. {
  40. "string": "name1",
  41. "int": 1,
  42. "array" : [100,200],
  43. "object": {}
  44. },
  45. "json2": "{\"string\":\"name2\",\"int\":2,\"array\":[300,400],\"object\":{}}",
  46. "content" : "new document"
  47. }
  48. }