4 _Documents_ represent the _things_ that we want to store in the _Search Data Service_ and are themselves, basically, a set of fields containing the data that we want to persist.
\r
8 _Document_ contents are specified as a simple JSON object. The structure of the _Document_ JSON should match the schema provided to the _Search Data Service_ when the _Index_ was created.
\r
10 For a discussion of how to specify the _Document Structure_, refer to [Index API](./INDEXES.md).
\r
12 **Example - Simple Document **
\r
16 "LastName": "Smith",
\r
20 **Example - Document With Nested Fields **
\r
23 "FirstName": "Sherlock",
\r
24 "LastName": "Holmes",
\r
26 "Street": "222B Baker",
\r
28 "Country": "England"
\r
35 Persists a _Document_ in an _Index_ in the _Search Data Service_.
\r
37 Note, that there are two variants of document creation: with and without supplying an id to associate with the document.
\r
39 **Create Document (No Id Specified)**
\r
41 If no _Id_ is provided by the client, then a unique identifier will be generated by the _Search Data Service_.
\r
46 https://{host}:9509/services/search-data-service/v1/search/indexes/{index}/documents/
\r
54 index - The name of the _Index_ to persist the _Document_ in.
\r
58 X-Create-Index = true = Allow index to be implicitly created if it does not already exist in the document store.
\r
62 Document contents expressed as a JSON object. (see **Syntax**)
\r
64 **Success Response**
\r
67 Header(s): ETag = ETag for the document instance that was just created.
\r
68 Body: URL identifying the document that was just created.
\r
70 {"url": "indexes/myindex/documents/AVgGq2jz4aZeqcwCmlQY"}
\r
76 500 - Internal Error
\r
80 **Create Document (Client Supplied Id)**
\r
82 If the client supplies an identifier for its document then that is what will be used for the document id.
\r
84 _NOTE: If a document id is supplied then it is the responsibility of the client to ensure uniqueness._
\r
89 https://{host}:9509/services/search-data-service/v1/search/indexes/{index}/documents/{id}
\r
97 index - The name of the _Index_ to persist the Document in.
\r
98 id - The identifier to associate with this Document.
\r
102 X-Create-Index = true = Allow index to be implicitly created if it does not already exist in the document store.
\r
104 **Request Payload**
\r
106 Document contents expressed as a JSON object. (see **Syntax**)
\r
108 **Success Response**
\r
111 Header(s): ETag = ETag for the document instance that was just created.
\r
112 Body: URL identifying the document that was just created.
\r
114 {"url": "indexes/myindex/documents/AVgGq2jz4aZeqcwCmlQY"}
\r
120 409 - Conflict -- Will occur if a document with that Id already exists
\r
121 500 - Internal Error
\r
126 ### Retrieve Document
\r
127 Perform a straight look up of a particular _Document_ by specifying its unique identifier.
\r
132 https://{host}:9509/services/search-data-service/v1/search/indexes/{index}/documents/{id}
\r
140 index - The name of the _Index_ to persist the Document in.
\r
141 id - The identifier to associate with this Document.
\r
143 **Request Payload**
\r
147 **Success Response**
\r
150 Header(s): ETag = ETag indicating the current version of the document.
\r
151 Body: Document contents expressed as a JSON object.
\r
154 "url": "indexes/myindex/documents/AVgGq2jz4aZeqcwCmlQY"
\r
156 "firstName": "Bob",
\r
157 "lastName": "Smith",
\r
166 500 - Internal Error
\r
170 ### Update Document
\r
171 Replace the contents of a document which already exists in the _Search Data Service_.
\r
173 **Optimistic Locking On Update**
\r
175 The _Search Data Service_ employs an optimistic locking mechanism on _Document_ updates which works as follows:
\r
177 The ETag response header field is set in the response for each document create or update to indicate the most recent version of the document in the document store.
\r
179 When performing a _Document_ update, this value must be supplied in the _If-Match_ field in the request header. Failure to supply this value, or failure to provide a value which matches the version in the document store will result in a request failure with a 412 (Precondition Failed) error.
\r
184 https://{host}:9509/services/search-data-service/v1/search/indexes/{index}/documents/{id}
\r
192 index - The name of the _Index_ to persist the Document in.
\r
193 id - The identifier to associate with this Document.
\r
197 Accept = application/json
\r
198 X-TransactionId = Unique id set by client (for logging purposes)
\r
199 X-FromAppId = Application identifier (for logging purposes)
\r
200 X-Create-Index = true = Allow index to be implicitly created if it does not already exist in the document store.
\r
201 Content-Type = application/json
\r
202 If-Match = The ETag value for the document to be updated.
\r
204 **Request Payload**
\r
206 Document contents expressed as a JSON object. (see Syntax Section)
\r
208 **Success Response**
\r
211 Header(s): ETag = ETag indicating the current version of the document.
\r
212 Body: URL identifying the document that was just created.
\r
214 {"url": "indexes/myindex/documents/AVgGq2jz4aZeqcwCmlQY"}
\r
221 412 - Precondition Failed -- Supplied ETag does not match the version in the document store.
\r
222 500 - Internal Error
\r
226 ### Delete Document
\r
227 Remove an existing _Index_ from the _Search Data Service_.
\r
228 Note that this results in the removal of all _Documents_ that are stored in the _Index_ at the time that the DELETE operation occurs.
\r
230 **Optimistic Locking On Update**
\r
232 As for _Document_ updates, the ETag value must be supplied in the _If-Match_ field in the request header.
\r
234 Failure to supply this value, or failure to provide a value which matches the version in the document store will result in a request failure with a 412 (Precondition Failed) error.
\r
239 https://{host}:9509/services/search-data-service/v1/search/indexes/{index}/documents/{id}
\r
247 index - The name of the _Index_ to persist the Document in.
\r
248 id - The identifier to associate with this Document.
\r
252 Accept = application/json
\r
253 X-TransactionId = Unique id set by client (for logging purposes)
\r
254 X-FromAppId = Application identifier (for logging purposes)
\r
255 Content-Type = application/json
\r
256 If-Match = The ETag value for the document to be deleted.
\r
258 **Request Payload**
\r
262 **Success Response**
\r
273 412 - Precondition Failed -- Supplied ETag does not match the version in the document store.
\r
274 500 - Internal Error
\r