Merge "Add version.properties file"
[aai/search-data-service.git] / DOCUMENTS.md
1 # Documents\r
2 \r
3 ## Overview\r
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
5 \r
6 \r
7 ## Syntax\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
9 \r
10 For a discussion of how to specify the _Document Structure_, refer to [Index API](./INDEXES.md). \r
11 \r
12 **Example - Simple Document **\r
13 \r
14     {\r
15        "FirstName": "Bob",\r
16        "LastName": "Smith",\r
17        "Age": 43\r
18     }\r
19 \r
20 **Example - Document With Nested Fields **\r
21 \r
22     {\r
23         "FirstName": "Sherlock",\r
24         "LastName": "Holmes",\r
25         "Address": {\r
26                 "Street": "222B Baker",\r
27                 "City": "London",\r
28                 "Country": "England"\r
29         }\r
30     }\r
31     \r
32 ## API\r
33 \r
34 ### Create Document\r
35 Persists a _Document_ in an _Index_ in the _Search Data Service_.\r
36 \r
37 Note, that there are two variants of document creation: with and without supplying an id to associate with the document.\r
38 \r
39 **Create Document (No Id Specified)**\r
40 \r
41 If no _Id_ is provided by the client, then a unique identifier will be generated by the _Search Data Service_.\r
42 \r
43 ---\r
44 **URL**\r
45 \r
46     https://{host}:9509/services/search-data-service/v1/search/indexes/{index}/documents/\r
47 \r
48 **Method** \r
49 \r
50     POST\r
51 \r
52 **URL Params**\r
53 \r
54     index - The name of the _Index_ to persist the _Document_ in.\r
55 \r
56 **Request Payload**\r
57 \r
58     Document contents expressed as a JSON object. (see **Syntax**) \r
59 \r
60 **Success Response**\r
61 \r
62     Code:      201\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
65                Example:\r
66                      {"url": "indexes/myindex/documents/AVgGq2jz4aZeqcwCmlQY"}\r
67     \r
68 **Error Response**\r
69 \r
70     400 - Bad Request\r
71     403 - Unauthorized\r
72     500 - Internal Error\r
73 \r
74 ---\r
75 \r
76 **Create Document (Client Supplied Id)**\r
77 \r
78 If the client supplies an identifier for its document then that is what will be used for the document id.\r
79 \r
80 _NOTE: If a document id is supplied then it is the responsibility of the client to ensure uniqueness._  \r
81 \r
82 ---\r
83 **URL**\r
84 \r
85     https://{host}:9509/services/search-data-service/v1/search/indexes/{index}/documents/{id}\r
86 \r
87 **Method** \r
88 \r
89     PUT\r
90 \r
91 **URL Params**\r
92 \r
93     index - The name of the _Index_ to persist the Document in.\r
94     id    - The identifier to associate with this Document.\r
95 \r
96 **Request Payload**\r
97 \r
98     Document contents expressed as a JSON object. (see **Syntax**) \r
99 \r
100 **Success Response**\r
101 \r
102     Code:      201\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
105                Example:\r
106                      {"url": "indexes/myindex/documents/AVgGq2jz4aZeqcwCmlQY"}\r
107     \r
108 **Error Response**\r
109 \r
110     400 - Bad Request\r
111     403 - Unauthorized\r
112     409 - Conflict -- Will occur if a document with that Id already exists\r
113     500 - Internal Error\r
114 \r
115 ---\r
116 \r
117 \r
118 ### Retrieve Document\r
119 Perform a straight look up of a particular _Document_ by specifying its unique identifier.\r
120 \r
121 ---\r
122 **URL**\r
123 \r
124     https://{host}:9509/services/search-data-service/v1/search/indexes/{index}/documents/{id}\r
125 \r
126 **Method** \r
127 \r
128     GET\r
129 \r
130 **URL Params**\r
131 \r
132     index - The name of the _Index_ to persist the Document in.\r
133     id    - The identifier to associate with this Document.\r
134 \r
135 **Request Payload**\r
136 \r
137     NONE \r
138 \r
139 **Success Response**\r
140 \r
141     Code:      200\r
142     Header(s): ETag = ETag indicating the current version of the document.\r
143     Body:      Document contents expressed as a JSON object.  \r
144                Example:\r
145                      {\r
146                          "url": "indexes/myindex/documents/AVgGq2jz4aZeqcwCmlQY"\r
147                          "content": {\r
148                              "firstName": "Bob",\r
149                              "lastName": "Smith",\r
150                              "age": 43\r
151                          }    \r
152                      }\r
153     \r
154 **Error Response**\r
155 \r
156     400 - Bad Request\r
157     404 - Not Found\r
158     500 - Internal Error\r
159 \r
160 ---\r
161 \r
162 ### Update Document\r
163 Replace the contents of a document which already exists in the _Search Data Service_.\r
164 \r
165 **Optimistic Locking On Update**\r
166 \r
167 The _Search Data Service_ employs an optimistic locking mechanism on _Document_ updates which works as follows:\r
168 \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
170 \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
172 \r
173 ---\r
174 **URL**\r
175 \r
176     https://{host}:9509/services/search-data-service/v1/search/indexes/{index}/documents/{id}\r
177 \r
178 **Method** \r
179 \r
180     PUT\r
181 \r
182 **URL Params**\r
183 \r
184     index - The name of the _Index_ to persist the Document in.\r
185     id    - The identifier to associate with this Document.\r
186 \r
187 **Request Header**\r
188 \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
194 \r
195 **Request Payload**\r
196 \r
197     Document contents expressed as a JSON object. (see Syntax Section) \r
198 \r
199 **Success Response**\r
200 \r
201     Code:      200\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
204                Example:\r
205                      {"url": "indexes/myindex/documents/AVgGq2jz4aZeqcwCmlQY"}\r
206     \r
207 **Error Response**\r
208 \r
209     400 - Bad Request\r
210     403 - Unauthorized\r
211     404 - Not Found\r
212     412 - Precondition Failed -- Supplied ETag does not match the version in the document store.\r
213     500 - Internal Error\r
214 \r
215 ---\r
216 \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
220 \r
221 **Optimistic Locking On Update**\r
222 \r
223 As for _Document_ updates, the ETag value must be supplied in the _If-Match_ field in the request header.  \r
224 \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
226 \r
227 ---\r
228 **URL**\r
229 \r
230     https://{host}:9509/services/search-data-service/v1/search/indexes/{index}/documents/{id}\r
231 \r
232 **Method** \r
233 \r
234     DELETE\r
235 \r
236 **URL Params**\r
237 \r
238     index - The name of the _Index_ to persist the Document in.\r
239     id    - The identifier to associate with this Document.\r
240 \r
241 **Request Header**\r
242 \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
248     \r
249 **Request Payload**\r
250 \r
251     NONE \r
252 \r
253 **Success Response**\r
254 \r
255     Code:      200\r
256     Header(s): None.\r
257     Body:      None.  \r
258     \r
259 **Error Response**\r
260 \r
261     400 - Bad Request\r
262     403 - Unauthorized\r
263     404 - Not Found\r
264     412 - Precondition Failed -- Supplied ETag does not match the version in the document store.\r
265     500 - Internal Error\r
266 \r
267 ---\r