| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- .. _http_json_insert:
- json/insert
- -----------
- 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``.
- Here's how you can index a simple document:
- ::
- {
- "index":"test",
- "id":1
- }
- 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:
- ::
- {
- "index":"test",
- "id":1,
- "doc":
- {
- "gid" : 10,
- "content" : "new document"
- }
- }
- The daemon will respond with a JSON object stating if the operation was successfull or not:
- ::
-
- {
- "_index": "test",
- "_id": 1,
- "created": true,
- "result": "created"
- }
-
-
- MVA attributes are inserted as arrays of numbers. JSON attributes can be inserted either as JSON objects or as strings containing escaped JSON:
- ::
- {
- "index":"test",
- "id":1,
- "doc":
- {
- "mva" : [1,2,3,4,5],
- "json1":
- {
- "string": "name1",
- "int": 1,
- "array" : [100,200],
- "object": {}
- },
- "json2": "{\"string\":\"name2\",\"int\":2,\"array\":[300,400],\"object\":{}}",
- "content" : "new document"
- }
- }
-
- To index a document in a cluster's index ``cluster`` property should be set along with ``index`` property:
- ::
- {
- "cluster":"nodes4",
- "index":"test",
- "id":1,
- "doc":
- {
- "gid" : 10,
- "content" : "new document"
- }
- }
|