<commit_before>## 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.

    {
        "successful": true,
        "query": {
            "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](../search_parameters/README.md) 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
<commit_msg>Update template_create_update.md<commit_after>## 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.

```json
{
    "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](../search_parameters/README.md) 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

{'fraction_non_alphanumeric': 0.15522145469321413, 'fraction_numerical': 0.009345794392523364, 'mean_word_length': 1.4838546922300706, 'pattern_counts': {'":': 78, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3231777', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1360, 'n_words': 355}