# Create/replace suggestion index

- Operation ID: `PutSuggestionIndexConfig`
- HTTP method: `PUT`
- Path: `/search/v2/suggestion-indices/{indexId}/config`
- [Human-readable API reference](https://hub.synerise.com/api-reference/ai-search#tag/Suggestions-Configuration/operation/PutSuggestionIndexConfig)

## Self-contained OpenAPI method

The fenced document below contains this method's documentation and all of its local references. It is self-contained; no category or master specification fetch is required.

```yaml
openapi: 3.0.0
info:
  title: Synerise Public API
  version: 1.9.1
paths:
  /search/v2/suggestion-indices/{indexId}/config:
    put:
      summary: Create/replace suggestion index
      description: |
        Create a suggestion index configuration or replace an existing one, given the index ID.

        ---

        **API consumers:** <a href="/api-reference/authorization?tag=Authorization&amp;operationId=profileLogin" target="_blank" rel="noopener">Workspace (Business Profile)</a>, <a href="/api-reference/authorization?tag=Authorization&amp;operationId=userLogin" target="_blank" rel="noopener">Synerise User</a>

        **API key permission required:** `ITEMS_SEARCH_CONFIG_SEARCH_UPDATE`

        **User role permission required:** `assets_search: update`
      operationId: PutSuggestionIndexConfig
      tags:
        - Suggestions Configuration
      security:
        - JWT: []
      parameters:
        - in: path
          name: indexId
          required: true
          description: ID of the index
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                indexName:
                  type: string
                  description: Name of the suggestion index
                description:
                  type: string
                  description: Description of the suggestion index
                author:
                  type: integer
                  description: ID of the user who created the suggestion index
                enabled:
                  type: boolean
                  description: When `true`, index is enabled and can be queried.
                sources:
                  type: object
                  description: Sources for the suggestions
                  properties:
                    indices:
                      type: array
                      description: A list of search indices
                      items:
                        type: object
                        properties:
                          indexId:
                            type: string
                            description: ID of the index
                          minPopularity:
                            type: integer
                            description: Minimum popularity of a query to be used as a suggestion
                            default: 5
                          minHits:
                            type: integer
                            description: Minimum search hits of a query to be used as a suggestion
                            default: 1
                          minLetters:
                            type: integer
                            description: Minimum required number of letters for a suggestion to remain
                            default: 2
                          daysInterval:
                            type: integer
                            description: Suggestions will be created from search statistics from last `daysInterval` days
                            default: 30
                          validate:
                            type: boolean
                            description: When `true`, the suggestions presence in searchable attributes is verified
                            default: false
                        required:
                          - indexId
                    external:
                      type: array
                      description: An array of external queries that can be used as suggestions
                      items:
                        type: object
                        properties:
                          query:
                            type: string
                            description: External query to be used as a suggestion
                          count:
                            type: integer
                            description: Hits of the external query - used to create the weight of the suggested query.
                        required:
                          - query
                          - count
                    generate:
                      type: array
                      description: |
                        A group of attributes to use for generating suggestions.

                        If the group consists of single facet, all values of the facet are used as suggestions.

                        If the group consists of more than one facet, all combinations of the facets' values are used.

                        **Example 1:**
                        - Given the `["brand"]` group, the generated suggestions are: `["apple", "samsung", "nokia"]`

                        - Given the `["color"]` group, the generated suggestions are: `["red", "blue"]`

                        **Example 2:**

                        Given the `["color", "brand"]` group, the generated suggestions are:<br/>
                        `["red apple", "red samsung", "red nokia", "blue apple", "blue samsung", "blue nokia"]`
                      items:
                        type: object
                        properties:
                          itemsCatalogId:
                            type: string
                            description: Id of a catalog from which attributes will be taken
                          attributes:
                            type: array
                            items:
                              type: string
                denylist:
                  type: array
                  description: Suggestions that will be ignored and *not* shown
                  items:
                    type: object
                    properties:
                      pattern:
                        type: string
                        description: Pattern (text) to be used while denylisting suggestions. If the suggestion matches the pattern in a way defined by `matchingType`, it's not shown.
                      matchingType:
                        type: string
                        description: |
                          
                          <span style="color:red"><strong>IMPORTANT</strong></span>: All patterns are case-**in**sensitive, including regex.

                          - Using Phrase matching, the suggestion must match the whole pattern exactly.

                          - Using FullWord matching, any word of the suggestion must exactly match the pattern.

                          - Using PartialWord matching, any word of the suggestion must partially match the pattern.

                          - Using RegularExpression matching, the pattern is treated as a regular expression and must match the suggestion.
                        enum:
                          - Phrase
                          - FullWord
                          - PartialWord
                          - RegularExpression
                        example: Phrase
              required:
                - indexName
                - enabled
                - sources
      responses:
        "200":
          description: Suggestion index config created or replaced successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  indexId:
                    type: string
                    description: ID of the index
                  indexName:
                    type: string
                    description: Name of the suggestion index
                  description:
                    type: string
                    description: Description of the suggestion index
                  author:
                    type: integer
                    description: ID of the user who created the suggestion index
                  enabled:
                    type: boolean
                    description: When `true`, index is enabled and can be queried.
                  sources:
                    type: object
                    description: Sources for the suggestions
                    properties:
                      indices:
                        type: array
                        description: A list of search indices
                        items:
                          type: object
                          properties:
                            indexId:
                              type: string
                              description: ID of the index
                            minPopularity:
                              type: integer
                              description: Minimum popularity of a query to be used as a suggestion
                              default: 5
                            minHits:
                              type: integer
                              description: Minimum search hits of a query to be used as a suggestion
                              default: 1
                            minLetters:
                              type: integer
                              description: Minimum required number of letters for a suggestion to remain
                              default: 2
                            daysInterval:
                              type: integer
                              description: Suggestions will be created from search statistics from last `daysInterval` days
                              default: 30
                            validate:
                              type: boolean
                              description: When `true`, the suggestions presence in searchable attributes is verified
                              default: false
                          required:
                            - indexId
                      external:
                        type: array
                        description: An array of external queries that can be used as suggestions
                        items:
                          type: object
                          properties:
                            query:
                              type: string
                              description: External query to be used as a suggestion
                            count:
                              type: integer
                              description: Hits of the external query - used to create the weight of the suggested query.
                          required:
                            - query
                            - count
                      generate:
                        type: array
                        description: |
                          A group of attributes to use for generating suggestions.

                          If the group consists of single facet, all values of the facet are used as suggestions.

                          If the group consists of more than one facet, all combinations of the facets' values are used.

                          **Example 1:**
                          - Given the `["brand"]` group, the generated suggestions are: `["apple", "samsung", "nokia"]`

                          - Given the `["color"]` group, the generated suggestions are: `["red", "blue"]`

                          **Example 2:**

                          Given the `["color", "brand"]` group, the generated suggestions are:<br/>
                          `["red apple", "red samsung", "red nokia", "blue apple", "blue samsung", "blue nokia"]`
                        items:
                          type: object
                          properties:
                            itemsCatalogId:
                              type: string
                              description: Id of a catalog from which attributes will be taken
                            attributes:
                              type: array
                              items:
                                type: string
                  denylist:
                    type: array
                    description: Suggestions that will be ignored and *not* shown
                    items:
                      type: object
                      properties:
                        pattern:
                          type: string
                          description: Pattern (text) to be used while denylisting suggestions. If the suggestion matches the pattern in a way defined by `matchingType`, it's not shown.
                        matchingType:
                          type: string
                          description: |
                            
                            <span style="color:red"><strong>IMPORTANT</strong></span>: All patterns are case-**in**sensitive, including regex.

                            - Using Phrase matching, the suggestion must match the whole pattern exactly.

                            - Using FullWord matching, any word of the suggestion must exactly match the pattern.

                            - Using PartialWord matching, any word of the suggestion must partially match the pattern.

                            - Using RegularExpression matching, the pattern is treated as a regular expression and must match the suggestion.
                          enum:
                            - Phrase
                            - FullWord
                            - PartialWord
                            - RegularExpression
                          example: Phrase
                  updatedAt:
                    type: string
                    format: date-time
                    description: Last update time in YYYY-MM-DDThh:mm:ssZ format (ISO 8601, UTC)
                  createdAt:
                    type: string
                    format: date-time
                    description: Creation time in YYYY-MM-DDThh:mm:ssZ format (ISO 8601, UTC)
        "500":
          description: An error occurred
          content:
            application/json:
              schema:
                type: object
                properties:
                  timestamp:
                    type: string
                    format: date-time
                    description: Time when the error occurred
                  status:
                    type: integer
                    description: Status code
                  error:
                    type: string
                    description: Summary of the error
                  message:
                    type: string
                    description: Description of the problem
                  path:
                    type: string
                    description: URL of the requested resource
                required:
                  - timestamp
                  - status
                  - message
      x-snr-doc-urls:
        - /api-reference/ai-search#tag/Suggestions-Configuration/operation/PutSuggestionIndexConfig
      x-codeSamples:
        - lang: cURL
          label: cURL
          source: |-
            curl --request PUT \
              --url https://api.synerise.com/search/v2/suggestion-indices/%7BindexId%7D/config \
              --header 'Authorization: Bearer REPLACE_BEARER_TOKEN' \
              --header 'content-type: application/json' \
              --data '{"indexName":"string","description":"string","author":0,"enabled":true,"sources":{"indices":[{"indexId":"string","minPopularity":5,"minHits":1,"minLetters":2,"daysInterval":30,"validate":false}],"external":[{"query":"string","count":0}],"generate":[{"itemsCatalogId":"string","attributes":["string"]}]},"denylist":[{"pattern":"string","matchingType":"Phrase"}]}'
        - lang: Python
          label: Python
          source: |-
            import http.client

            conn = http.client.HTTPSConnection("api.synerise.com")

            payload = "{\"indexName\":\"string\",\"description\":\"string\",\"author\":0,\"enabled\":true,\"sources\":{\"indices\":[{\"indexId\":\"string\",\"minPopularity\":5,\"minHits\":1,\"minLetters\":2,\"daysInterval\":30,\"validate\":false}],\"external\":[{\"query\":\"string\",\"count\":0}],\"generate\":[{\"itemsCatalogId\":\"string\",\"attributes\":[\"string\"]}]},\"denylist\":[{\"pattern\":\"string\",\"matchingType\":\"Phrase\"}]}"

            headers = {
                'Authorization': "Bearer REPLACE_BEARER_TOKEN",
                'content-type': "application/json"
                }

            conn.request("PUT", "/search/v2/suggestion-indices/%7BindexId%7D/config", payload, headers)

            res = conn.getresponse()
            data = res.read()

            print(data.decode("utf-8"))
        - lang: JavaScript
          label: JavaScript
          source: |-
            const data = JSON.stringify({
              "indexName": "string",
              "description": "string",
              "author": 0,
              "enabled": true,
              "sources": {
                "indices": [
                  {
                    "indexId": "string",
                    "minPopularity": 5,
                    "minHits": 1,
                    "minLetters": 2,
                    "daysInterval": 30,
                    "validate": false
                  }
                ],
                "external": [
                  {
                    "query": "string",
                    "count": 0
                  }
                ],
                "generate": [
                  {
                    "itemsCatalogId": "string",
                    "attributes": [
                      "string"
                    ]
                  }
                ]
              },
              "denylist": [
                {
                  "pattern": "string",
                  "matchingType": "Phrase"
                }
              ]
            });

            const xhr = new XMLHttpRequest();
            xhr.withCredentials = true;

            xhr.addEventListener("readystatechange", function () {
              if (this.readyState === this.DONE) {
                console.log(this.responseText);
              }
            });

            xhr.open("PUT", "https://api.synerise.com/search/v2/suggestion-indices/%7BindexId%7D/config");
            xhr.setRequestHeader("Authorization", "Bearer REPLACE_BEARER_TOKEN");
            xhr.setRequestHeader("content-type", "application/json");

            xhr.send(data);
        - lang: Node.js
          label: Node.js
          source: |-
            const http = require("https");

            const options = {
              "method": "PUT",
              "hostname": "api.synerise.com",
              "port": null,
              "path": "/search/v2/suggestion-indices/%7BindexId%7D/config",
              "headers": {
                "Authorization": "Bearer REPLACE_BEARER_TOKEN",
                "content-type": "application/json"
              }
            };

            const req = http.request(options, function (res) {
              const chunks = [];

              res.on("data", function (chunk) {
                chunks.push(chunk);
              });

              res.on("end", function () {
                const body = Buffer.concat(chunks);
                console.log(body.toString());
              });
            });

            req.write(JSON.stringify({
              indexName: 'string',
              description: 'string',
              author: 0,
              enabled: true,
              sources: {
                indices: [
                  {
                    indexId: 'string',
                    minPopularity: 5,
                    minHits: 1,
                    minLetters: 2,
                    daysInterval: 30,
                    validate: false
                  }
                ],
                external: [{query: 'string', count: 0}],
                generate: [{itemsCatalogId: 'string', attributes: ['string']}]
              },
              denylist: [{pattern: 'string', matchingType: 'Phrase'}]
            }));
            req.end();
        - lang: PHP
          label: PHP
          source: |-
            <?php

            $request = new HttpRequest();
            $request->setUrl('https://api.synerise.com/search/v2/suggestion-indices/%7BindexId%7D/config');
            $request->setMethod(HTTP_METH_PUT);

            $request->setHeaders([
              'Authorization' => 'Bearer REPLACE_BEARER_TOKEN',
              'content-type' => 'application/json'
            ]);

            $request->setBody('{"indexName":"string","description":"string","author":0,"enabled":true,"sources":{"indices":[{"indexId":"string","minPopularity":5,"minHits":1,"minLetters":2,"daysInterval":30,"validate":false}],"external":[{"query":"string","count":0}],"generate":[{"itemsCatalogId":"string","attributes":["string"]}]},"denylist":[{"pattern":"string","matchingType":"Phrase"}]}');

            try {
              $response = $request->send();

              echo $response->getBody();
            } catch (HttpException $ex) {
              echo $ex;
            }
        - lang: Java
          label: Java
          source: |-
            HttpResponse<String> response = Unirest.put("https://api.synerise.com/search/v2/suggestion-indices/%7BindexId%7D/config")
              .header("Authorization", "Bearer REPLACE_BEARER_TOKEN")
              .header("content-type", "application/json")
              .body("{\"indexName\":\"string\",\"description\":\"string\",\"author\":0,\"enabled\":true,\"sources\":{\"indices\":[{\"indexId\":\"string\",\"minPopularity\":5,\"minHits\":1,\"minLetters\":2,\"daysInterval\":30,\"validate\":false}],\"external\":[{\"query\":\"string\",\"count\":0}],\"generate\":[{\"itemsCatalogId\":\"string\",\"attributes\":[\"string\"]}]},\"denylist\":[{\"pattern\":\"string\",\"matchingType\":\"Phrase\"}]}")
              .asString();
servers:
  - description: Microsoft Azure EU
    url: https://api.synerise.com
  - description: Microsoft Azure USA
    url: https://api.azu.synerise.com
  - description: Google Cloud Platform
    url: https://api.geb.synerise.com
tags:
  - name: Suggestions Configuration
components:
  securitySchemes:
    JWT:
      type: http
      scheme: bearer
      description: |-
        JWT Bearer token. The header looks like this: `Bearer {JWT}`

        Remember to include the space between 'Bearer' and the token.

        Generate a token via the **Authorization** endpoints.
```
