Update API

With the Update API, you can post updates to existing documents in a named data platform. Data can be posted in either JSON or XML document representation directly (for example via JavaScript on the client side) or by simply pointing an HTML form at the appropriate endpoint.

Resource URI

/twigkit/api/core/services/platform

POST update/{platform}/form

Any HTML form data can be posted to this endpoint, which in turn translates the form data into a document which gets posted to the search platform. Each input element in the form will be mapped to a field with the corresponding name. This assumes there is a form attribute named id (which can be a hidden element) that denotes the unique identifier of the document that gets updated (this can be either a new ID or it can point to an existing document).

Path parameters

platform
Required
The configuration name of the search platform that should process the query.
Example values: my.platform, platform.solr.news

Note
The platform configuration must have the property readOnly: false.

Example

In this example, we assume you have configured a platform to update blog entries, at configuration entry platforms.blog. This can be backed by any of the data providers supported by Appkit. You must ensure that readOnly: false is set in the platform configuration. For your own testing, you can replace platforms.blog with the configuration of your own data provider.

Create a new JSP or HTML page in your application, and add this form block somewhere in the body of the page:

<form action="/twigkit/api/core/services/platform/update/platforms.blog/form" method="post" title="Update a blog post">
    <div>
        <label for="title">Title</label>
        <input type="text" id="title" name="title" />
    </div>
    <div>
        <label for="main_text">Text</label>
        <input type="text" id="main_text" name="main_text" />
    </div>
    <input type="hidden" id="id" name="id" value="my_id" />
    <div class="button">
        <button type="submit">Update blog</button>
    </div>
</form>

Assuming you have filled the form in with "Breaking news" and "Read all about it", posting the form would then redirect you to the REST service, which produces this output:

<?xml version="1.0"?>
<content xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" id="my_id" score="0.0">
	<fields>
		<fld name="title">
			<val>
				<act xsi:type="xs:string">Breaking news</act>
				<dsp>Breaking news</dsp>
			</val>
		</fld>
		<fld name="main_text">
			<val>
				<act xsi:type="xs:string">Read all about it</act>
				<dsp>Read all about it</dsp>
			</val>
		</fld>
	</fields>
	<related/>
	<facts/>
</content>

To verify that the content was correctly written to the index, you can do a quick search like this (assuming your server is running on localhost on port 8080). Here, we assume your endpoint is protected by BASIC authentication and you log on as a "test" user:

curl -u test:**** 'http://localhost:8080/twigkit/api/core/services/platform/search/platforms.blog?q=breaking+news'

POST update/{platform}

Posts a document in JSON or XML form to be updated in the given platform. Accepts a list of twigkit.model.Content objects, in this JSON format:

[
	{
		"id": "1",
		"fields": {
			"field_1": {
				"name": "field_1",
				"val": [
					"value_1"
				]
			},
			"field_2": {
				"name": "field_2",
				"val": [
					"value_2",
					"value_2_2"
				]
			}
		}
	},
	{
		"id": "2",
		"fields": {
			"field_1": {
				"name": "field_1",
				"val": [
					"value_2"
				]
			}
		}
	}
]

Path parameters

platform
Required
The configuration name of the search platform that should process the query.
Example values: my.platform, platform.solr.news

Note
The platform configuration must have the property readOnly: false.

Example

In this example, we assume that you have configured a platforms.blog data provider as in the example above. As before, we assume your endpoint is protected by BASIC authentication and you log on as a "test" user. Also, note that platforms.blog has the property readOnly: false set to allow data push.

curl -u test:**** -H "Content-Type: application/json" -X POST -d '[{"id":"my_id","fields": { "title": { "name": "title", "val": [ "Breaking news" ] }, "main_text": { "name": "main_text", "val": [ "Read all about it" ] } } }]' "http://localhost:8080/twigkit/api/core/services/platform/update/platforms.blog"

This produces this JSON response:

[
	{
		"id": "my_id",
		"fields": {
			"title": {
				"name": "title",
				"val": [
					"Breaking news"
				]
			},
			"main_text": {
				"name": "main_text",
				"val": [
					"Read all about it"
				]
			}
		},
		"facts": {},
		"score": 0.0,
		"related": []
	}
]