Create or update a search template based on fields

Use this API to create or update a search template.

Requirement: OpenSearchServer v1.5

Call parameters

URL: /services/rest/index/{index_name}/search/field/{template_name}

Method: PUT

Header:

  • Content-Type (required): application/json
  • Accept (optional returned type): application/json or application/xml

URL parameters:

  • index_name (required): The name of the index.
  • template_name (required): The name of the search template.

Raw data (PUT):
The search field query either in JSON or XML format.

{
"start": 0,
"rows": 10,
"lang": "ENGLISH",
"operator": "AND",
"collapsing": {
"max": 2,
"mode": "OFF",
"type": "OPTIMIZED"
},
"returnedFields": [
"url"
],
"snippets": [
{
"field": "title",
"tag": "em",
"separator": "...",
"maxSize": 200,
"maxNumber": 1,
"fragmenter": "NO"
},
{
"field": "content",
"tag": "em",
"separator": "...",
"maxSize": 200,
"maxNumber": 1,
"fragmenter": "SENTENCE"
}
],
"enableLog": false,
"searchFields": [
{
"field": "title",
"mode": "TERM_AND_PHRASE",
"boost": 10
},
{
"field": "content",
"mode": "TERM_AND_PHRASE",
"boost": 1
},
{
"field": "titleExact",
"mode": "TERM_AND_PHRASE",
"boost": 10
},
{
"field": "contentExact",
"mode": "TERM_AND_PHRASE",
"boost": 1
}
]
}

See page List of available parameters for search queries for the full list of parameters.

Success response

The search template has been created or updated.

HTTP code:
200

Content (application/json):

{
"successful": true,
"info": "Template updated: my_search"
}

Error response

The creation/update failed. The reason is provided in the content.

HTTP code:
500

Sample call

Using CURL:

curl -XPUT -H "Content-Type: application/json" \
-d '...' \
http://localhost:8080/services/rest/index/my_index/search/field/my_search

View/edit on GitHub