RESTful API

Using the RESTful API of the SRCH2 engine, a user can send requests to insert new records, delete existing records, and update existing records. The engine has a background thread that periodically merges the inserted/deleted/updated records into the indexes, based on two parameters specified in the configuration file, namely "mergeEveryNSeconds" (time interval) and "mergeEveryMWrites" (number of write requests). Note that each RESTful request needs to use a proper URL encoder to be converted to characters in a format that can be transmitted properly.

1. Insert

This request adds a record or a list of records to the indexes. The request body should contain a single JSON object or an array of JSON objects, which should meet the following requirements:

Here are two examples:

 curl "http://127.0.0.1:8081/docs" -i -X PUT -d '{"id" : "1234", "name" : "Toy Story", "category" : "shop"}'
 curl "http://127.0.0.1:8081/docs" -i -X PUT -d '[{"id" : "1234", "name" : "Toy Story", "category" : "shop"},{"id" : "5678", "name" : "Toy Story II", "category" : "shop"}]'

2. Delete

This request deletes a record from the indexes. It needs to provide the primary key of the record to be deleted. The primary key can be sent in the query string one time per record. Here is an example:

 curl "http://127.0.0.1:8081/docs?name_of_your_primaryKey=1234" -i -X DELETE

3. Update

This request updates a record or an array of records in the indexes. For each record in the request, if the id is already in the index, the record will be updated. Otherwise, the record will be inserted. In other words, the engine is doing the "upsert" logic.

The request body should contain a JSON object or an array of JSON objects, which should meet the following requirements:

Here are two examples:

 curl "http://127.0.0.1:8081/update" -i -X PUT -d '{"id":"123","name":"Brave", "category":"shop"}'
 curl "http://127.0.0.1:8081/update" -i -X PUT -d '[{"id":"123","name":"Brave", "category":"shop"},{"id":"456","name":"Tom", "category":"shop"}]'

Internally the engine implements the update of a record by first deleting the old record, then inserting the new record.