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 Document contents expressed as a JSON object. (see **Syntax**)
\r
60 **Success Response**
\r
63 Header(s): ETag = ETag for the document instance that was just created.
\r
64 Body: URL identifying the document that was just created.
\r
66 {"url": "indexes/myindex/documents/AVgGq2jz4aZeqcwCmlQY"}
\r
72 500 - Internal Error
\r
76 **Create Document (Client Supplied Id)**
\r
78 If the client supplies an identifier for its document then that is what will be used for the document id.
\r
80 _NOTE: If a document id is supplied then it is the responsibility of the client to ensure uniqueness._
\r
85 https://{host}:9509/services/search-data-service/v1/search/indexes/{index}/documents/{id}
\r
93 index - The name of the _Index_ to persist the Document in.
\r
94 id - The identifier to associate with this Document.
\r
98 Document contents expressed as a JSON object. (see **Syntax**)
\r
100 **Success Response**
\r
103 Header(s): ETag = ETag for the document instance that was just created.
\r
104 Body: URL identifying the document that was just created.
\r
106 {"url": "indexes/myindex/documents/AVgGq2jz4aZeqcwCmlQY"}
\r
112 409 - Conflict -- Will occur if a document with that Id already exists
\r
113 500 - Internal Error
\r
118 ### Retrieve Document
\r
119 Perform a straight look up of a particular _Document_ by specifying its unique identifier.
\r
124 https://{host}:9509/services/search-data-service/v1/search/indexes/{index}/documents/{id}
\r
132 index - The name of the _Index_ to persist the Document in.
\r
133 id - The identifier to associate with this Document.
\r
135 **Request Payload**
\r
139 **Success Response**
\r
142 Header(s): ETag = ETag indicating the current version of the document.
\r
143 Body: Document contents expressed as a JSON object.
\r
146 "url": "indexes/myindex/documents/AVgGq2jz4aZeqcwCmlQY"
\r
148 "firstName": "Bob",
\r
149 "lastName": "Smith",
\r
158 500 - Internal Error
\r
162 ### Update Document
\r
163 Replace the contents of a document which already exists in the _Search Data Service_.
\r
165 **Optimistic Locking On Update**
\r
167 The _Search Data Service_ employs an optimistic locking mechanism on _Document_ updates which works as follows:
\r
169 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
171 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
176 https://{host}:9509/services/search-data-service/v1/search/indexes/{index}/documents/{id}
\r
184 index - The name of the _Index_ to persist the Document in.
\r
185 id - The identifier to associate with this Document.
\r
189 Accept = application/json
\r
190 X-TransactionId = Unique id set by client (for logging purposes)
\r
191 X-FromAppId = Application identifier (for logging purposes)
\r
192 Content-Type = application/json
\r
193 If-Match = The ETag value for the document to be updated.
\r
195 **Request Payload**
\r
197 Document contents expressed as a JSON object. (see Syntax Section)
\r
199 **Success Response**
\r
202 Header(s): ETag = ETag indicating the current version of the document.
\r
203 Body: URL identifying the document that was just created.
\r
205 {"url": "indexes/myindex/documents/AVgGq2jz4aZeqcwCmlQY"}
\r
212 412 - Precondition Failed -- Supplied ETag does not match the version in the document store.
\r
213 500 - Internal Error
\r
217 ### Delete Document
\r
218 Remove an existing _Index_ from the _Search Data Service_.
\r
219 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
221 **Optimistic Locking On Update**
\r
223 As for _Document_ updates, the ETag value must be supplied in the _If-Match_ field in the request header.
\r
225 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
230 https://{host}:9509/services/search-data-service/v1/search/indexes/{index}/documents/{id}
\r
238 index - The name of the _Index_ to persist the Document in.
\r
239 id - The identifier to associate with this Document.
\r
243 Accept = application/json
\r
244 X-TransactionId = Unique id set by client (for logging purposes)
\r
245 X-FromAppId = Application identifier (for logging purposes)
\r
246 Content-Type = application/json
\r
247 If-Match = The ETag value for the document to be deleted.
\r
249 **Request Payload**
\r
253 **Success Response**
\r
264 412 - Precondition Failed -- Supplied ETag does not match the version in the document store.
\r
265 500 - Internal Error
\r