1 # Search Engine Micro Service
3 The _Search Engine_ micro service exposes APIs via REST which allow clients to interact with the search database back end without requiring direct knowledge of or interaction with the underlying technology.
6 This section establishes some of the terminology and concepts that relate to interacting with the _Search Engine_ service.
7 A much more detailed examination of these concepts can be found on the [Search Engine Design Share](http://d2athenaconf:8090/confluence/display/AAI/AAI-4633%3A+Search+DB+Abstraction%3A+Expose+REST+Interface) Confluence page.
10 _Documents_ are the _things_ that we want to put into our document store. At its most basic, a _document_ is a collection of _fields_ which contain the data that we want to be able to store and query.
12 _Fields_ are defined as having a name, a type, and optional parameters indicating whether or not the field is intended to be searchable, and if so, how it should be indexed.
15 An _index_ is essentially a collection of _documents_. It is the top-level container into which we will store our documents. A single data store may have multiple _indexes_ for the purposes of segregating different types of data (most queries are performed across all documents within *single* instance).
20 ### Building The Micro Service
22 After checking out the project, execute the following Maven command from the project's top level directory:
26 ### Running The Micro Service Locally
27 To run the microservice in your local environment, execute the following Maven command from the project's top level directory:
31 ### Running The Micro Service Within An Eclipse Environment
32 It is often extremely useful to be able to run a micro service from within Eclipse in order to set breakpoints and perform general debugging activities.
34 For a good reference on how to launch any of the D2 micro services from within an Eclipse environment, refer to the following Confluence page: [Running An AJSC Container Within Eclipse](http://d2athenaconf:8090/confluence/pages/viewpage.action?pageId=1840887#DevelopingMicroserviceswithAT&T-RunninganAJSCContainerwithinEclipse)
41 The _Search Database Abstraction_ micro service supports the standard echo service to allow it to be 'pinged' to verify that the service is up and responding.
43 The echo service is reachable via the following REST end point:
45 http://{host}:9509/services/search-data-service/v1/jaxrsExample/jaxrs-services/echo/{input}
48 The _Search Engine_ service supports simple creation and deletion of document indexes via the following REST API calls:
52 URL : https://<host>:9509/services/search-data-service/v1/search/indexes/<index>/
53 URL Params : index - The name of the index to be created.
55 A document structure expressed as json.
58 {"url": "< resource location of the index >"
62 URL : http://<host>:9509/services/search-data-service/v1/search/indexes/<index>/
63 URL Params : index - The name of the index to be deleted.
70 ##### Create Document Without Specifying a Document Identifier
71 Documents can be created via a POST request with no document identifier specified. In this case the document store will generate an identifier to associate with the document.
74 URL : https://<host>:9509/services/search-data-service/v1/search/indexes/<index>/documents/
75 URL Params : index - The name of the index to create the document in.
77 Document contents expressed as a JSON object containing key/value pairs.
80 { "etag": "string", "url": "string" }
82 ##### Create or Update Document With a Specified Document Identifier
83 Documents can also be created via a PUT request which includes an identifier to associate with the document. The put endpoint is actually used for both creates and updates, where this is distinguished as follows:
84 * If the request header DOES NOT include a value in the If-Match field, then the request is assumed to be a document create.
85 * If the request header DOES contain a value in the If-Match field, then the request is assumed to be a document update.
88 URL : https://<host>:9509/services/search-data-service/v1/search/indexes/<index>/documents<document id>
89 URL Params : index - The name of the index to create or update the document in.
90 document id - The identifier of the document to be created or updated.
92 Document contents expressed as a JSON object containing key/value pairs.
95 { "etag": "string", "url": "string"}
97 ##### Delete a Document
100 URL : https://<host>:9509/services/search-data-service/v1/search/indexes/<index>/documents<document id>
101 URL Params : index - The name of the index to remove the document from.
102 document id - the identifier of the document to be deleted.
106 ##### Retrieve a Document
109 URL : https://<host>:9509/services/search-data-service/v1/search/indexes/<index>/documents<document id>
110 URL Params : index - The name of the index to retrieve the document from.
111 document id - the identifier of the document to be retrieved.
116 ### Searching the Document Store
117 Search statements are passed to the _Search Data Service_ as a JSON object which is structured as follows:
120 * A "filter" stanza defines a set of queries to be run in _non-scoring-mode_ to reduce the document set to a smaller subset to be searched.
121 * The filter stanza is optional - omitting it implies that the query is _unfiltered_.
122 * This stanza is represented as a JSON object with the following structure:
125 "all": [ { query }, { query },....{ query }],
126 "any": [ { query }, { query },....{ query }]
130 * the _all_ list defines a set of queryies such that ALL queries in the list must be satisfied for the document to pass the filter.
131 * the _any_ list defines a set of queryies such that ANY single query in the list must be satisfied for the document to pass the filter.
134 The following types of query statements are supported by the _Search Data Service_:
138 A term query attempts to match the literal value of a field, with no advanced parsing or analysis of the query string. This type of query is most appropriate for structured data like numbers, dates and enums, rather than full text fields.
140 // Find documents where the specified field contains the supplied value
145 // Find documents where the specified field DOES NOT contain the supplied value
152 Parsed queries apply a query parser to the supplied query string in order to determine the exact query to apply to the specified field.
153 The query string is parsed into a series of terms and operators, as described below:
155 Terms may be any of the following:
157 * exact phrases, as denoted by enclosing the phrase in open and close quotations. Example: "this is my exact phrase"
158 * regular expressions, as denoted by wrapping the expressing in forward slash ( / ) character. Example: /joh?n(ath[oa]n)/
160 The supported operators are as follows:
161 * AND - Both terms to the left or right of the operator MUST be present
162 * OR - Either the term to the left or right of the operator MUST be present
163 * NOT - The term to the right of the operator MUST NOT be present.
166 "field": "fieldname",
167 "query-string": "string"
172 Range queries match fields whose term value falls within the specified numeric or date range.
173 Supported bounds operators include:
175 * gte - Greater than or equal to
177 * lte - Less than or equal to
180 "field": "fieldname",
186 The following snippet illustrates a search statement describing a filtered query which uses examples of all of the supported query types:
190 "all": [{"range": {"field": "timestamp", "lte": "2016-12-01T00:00:00.558+03:00"}}],
195 {"match": {"field": "name", "value": "Bob"}},
196 {"parsed-query": {"field": "street-name", "query-string": "Main OR First"}},
197 {"range": {"field": "street-number", "gt": 10, "lt": 50}}
204 URL : https://<host>:9509/services/search-data-service/v1/search/indexes/<index>/query
205 URL Params : index - The name of the index to apply the query to.
210 "all": [ { query }, { query },....{ query }],
211 "any": [ { query }, { query },....{ query }]
223 Bulk operations allow the client to bundle a number of actions into a single REST request.
224 It is important to note that individual operations bundled into a bulk request are considered by the _Search Service_ to be completely independent operations. This has a few important consequences:
225 * No guarantees are made with respect to the order in which the individual operations will be processed by the document store.
226 * There is no implied transactionality between the operations. Individual operations my succeed or fail independently of one another, and it is entirely possible for the client to receive back a result set indicating a mix of success and failure results for the individual operations.
228 ##### Submit Bulk Request
230 URL : http://<host>:9509/services/search-data-service/v1/search/bulk/
233 A json structure containing all of the bundled actions to be performed.
234 It must correspond to the following format:
236 { "operation": {{<metaData>}, {<document>},
237 { "operation": {{<metaData>}, {<document>},
240 { "operation": {{<metaData>}, {<document>},
244 operation - Is one of: "create", "update", or "delete"
246 metaData - A structure containing meta-data associated with the individual operation to be performed. Valid fields include:
247 "url" - The resource identifier of the document to be operated on.
248 "etag" - Identifies the version of the document to be acted on. Required for "update" and "delete" operations.
250 document - The document contents for "create" and "update" operations.
254 {"create": {"metaData": {"url": "/services/search-data-service/v1/indexes/the-index/documents/1"}, "document": {"f1": "v1", "f2": "v2"}}},
255 {"create": {"metaData": {"url": "/services/search-data-service/indexes/the-index/documents/2"}, "document": {"f1": "v1", "f2": "v2"}}},
256 {"update": {"metaData": {"url": "/services/search-data-service/v1/search/indexes/the-index/documents/8", "etag": "1"}, "document": {"f1": "v1a", "f2": "v2a"}}},
257 {"delete": {"metaData": {"url": "/services/search-data-service/v1/search/indexes/the-index/documents/99", "etag": "3"}}}
261 The response body will contain an aggregation of the collective results as well as separate status codes for each of the operations in the request.
264 "total_operations": 4,
268 {"operation": "create", "url": "/services/search-data-service/v1/search/indexes/the-index/documents/1", "etag": "1", "status-code": "201", "status-message": "OK"},
269 {"operation": "create", "url": "/services/search-data-service/v1/search/indexes/the-index/documents/2", "etag": "1", "status-code": "201", "status-message": "OK"},
270 {"operation": "update", "url": "/services/search-data-service/v1/search/indexes/the-index/documents/8", "etag": "2", "status-code": "200", "status-message": "OK"},
271 {"operation": "delete", "url": "/services/search-data-service/v1/search/indexes/the-index/documents/2", "status-code": "200", "status-message": "OK"}