---
title: Custom Attributes
slug: indexing-apis/custom-attributes
docTags: 
createdAt: 2023-10-12T15:17:00.726Z
---

In the [Swagger/OpenAPI Specification](docId\:W5iVV5Q4JjBfFywxDS5p8), you will find that we have some predefined attributes for the item. That will not suffice all the use cases, e.g. you have brand, color, size, etc fields for your product.

Before indexing the additional attributes, the attribute definition needs to be created. Details of various options are available in the API Schema.

:::ApiMethodV2
```json
{
  "name": "Add custom attribute: brand",
  "method": "PUT",
  "url": "https://indexing-api.ksearchnet.com/v2/attributes/brand",
  "description": "",
  "tab": "examples",
  "examples": {
    "languages": [
      {
        "id": "xOBGdm4j1d4of8rZLyuHq",
        "language": "json",
        "code": "{\n  \"label\": {\n    \"default\": \"Brand Label\"\n  },\n  \"searchable\": true,\n  \"filterable\": true,\n  \"returnable\": true,\n  \"datatype\": \"STRING\"\n}\n",
        "customLabel": "Request Body (JSON)"
      }
    ],
    "selectedLanguageId": "xOBGdm4j1d4of8rZLyuHq"
  },
  "results": {
    "languages": [
      {
        "id": "blif1oGwvbqovmU2FClQc",
        "language": "200",
        "customLabel": "",
        "code": "{\n      \"message\": \"Attribute saved successfully.\"\n}"
      }
    ],
    "selectedLanguageId": "blif1oGwvbqovmU2FClQc"
  },
  "request": {
    "pathParameters": [],
    "queryParameters": [],
    "headerParameters": [
      {
        "name": "X-KLEVU-AUTH-ALGO",
        "kind": "required",
        "type": "string",
        "description": "This is the algorithm used to create the security bearer token. ",
        "children": []
      },
      {
        "name": "X-KLEVU-TIMESTAMP",
        "kind": "required",
        "type": "string",
        "description": "This should be your current time while generating the request. It is used to keep the request secured and discourage request relays.",
        "children": []
      },
      {
        "name": "X-KLEVU-APIKEY",
        "kind": "required",
        "type": "string",
        "description": "This is the API Key of your store. Please refer to the Klevu Merchant Centre manual to understand where to get this key from.",
        "children": []
      },
      {
        "name": "Content-Type",
        "kind": "required",
        "type": "string",
        "description": "This needs to be application/JSON as this request body contains a JSON.",
        "children": []
      }
    ],
    "bodyDataParameters": [],
    "formDataParameters": []
  },
  "currentNewParameter": {
    "label": "Header Parameter",
    "value": "headerParameters"
  },
  "autoGeneratedAnchorSlug": "add-custom-attribute-brand",
  "legacyHash": "KizitdZDHFQ2TWWLGBzzf"
}
```
:::

:::ApiMethodV2
```json
{
  "name": "Add custom attribute: size",
  "method": "PUT",
  "url": "https://indexing-api.ksearchnet.com/v2/attributes/size",
  "description": "",
  "tab": "examples",
  "examples": {
    "languages": [
      {
        "id": "xOBGdm4j1d4of8rZLyuHq",
        "language": "json",
        "code": "{\n  \"label\": {\n    \"default\": \"Size Label\"\n  },\n  \"searchable\": true,\n  \"filterable\": true,\n  \"returnable\": true,\n  \"datatype\": \"STRING\"\n}",
        "customLabel": "Request Body (JSON)"
      }
    ],
    "selectedLanguageId": "xOBGdm4j1d4of8rZLyuHq"
  },
  "results": {
    "languages": [
      {
        "id": "blif1oGwvbqovmU2FClQc",
        "language": "200",
        "customLabel": "",
        "code": "{\n     \"message\": \"Attribute saved successfully.\"\n}"
      }
    ],
    "selectedLanguageId": "blif1oGwvbqovmU2FClQc"
  },
  "request": {
    "pathParameters": [],
    "queryParameters": [],
    "headerParameters": [
      {
        "name": "X-KLEVU-AUTH-ALGO",
        "kind": "required",
        "type": "string",
        "description": "This is the algorithm used to create the security bearer token. ",
        "children": []
      },
      {
        "name": "X-KLEVU-TIMESTAMP",
        "kind": "required",
        "type": "string",
        "description": "This should be your current time while generating the request. It is used to keep the request secured and discourage request relays.",
        "children": []
      },
      {
        "name": "X-KLEVU-APIKEY",
        "kind": "required",
        "type": "string",
        "description": "This is the API Key of your store. Please refer to the Klevu Merchant Centre manual to understand where to get this key from.",
        "children": []
      },
      {
        "name": "Content-Type",
        "kind": "required",
        "type": "string",
        "description": "This needs to be application/JSON as this request body contains a JSON.",
        "children": []
      }
    ],
    "bodyDataParameters": [],
    "formDataParameters": []
  },
  "currentNewParameter": {
    "label": "Header Parameter",
    "value": "headerParameters"
  },
  "autoGeneratedAnchorSlug": "add-custom-attribute-size",
  "legacyHash": "XZyCEKc_Ly6PLZ2IsSk93"
}
```
:::

The above API has created two attributes, brand and size. Important to note that the attribute key should be sanitized, without any special characters. This needs to be done only once, not every time you index products. For more information on the supported data types, please refer to the [Data Types](docId\:Ib9Ci4fOeIfFefORoxofO).

Once the attribute definition is created, let's index the product.

:::BlockQuote
\[
&#x20; \{
&#x20;   "id": "1",
&#x20;   "type": "KLEVU\_PRODUCT",
&#x20;   "attributes": \{
&#x20;     "name": \{ "default": "Product 1" },
&#x20;      "brand" : "UCB",
&#x20;      "size" : "s"
&#x20;   }
&#x20; },
&#x20; \{
&#x20;   "id": "2",
&#x20;   "type": "KLEVU\_PRODUCT",
&#x20;   "attributes": \{
&#x20;     "name": \{ "default": "Product 2" },
&#x20;      "brand" : "UCB",
&#x20;      "size" : "m"
&#x20;   }
&#x20; }
]
:::

In the above example, we have indexed the two new attributes to the product, i.e. brand and size.

### Example for MULTIVALUE attribute registration

:::ApiMethodV2
```json
{
  "name": "Add custom attribute: materials",
  "method": "PUT",
  "url": "https://indexing-api.ksearchnet.com/v2/attributes/materials",
  "description": "",
  "tab": "examples",
  "examples": {
    "languages": [
      {
        "id": "xOBGdm4j1d4of8rZLyuHq",
        "language": "curl",
        "code": "curl --location --request PUT 'https://indexing-api.ksearchnet.com/v2/attributes/custom1' \\\n--header 'X-KLEVU-AUTH-ALGO: HmacSHA384' \\\n--header 'X-KLEVU-TIMESTAMP: 2023-07-10T08:38:00Z' \\\n--header 'X-KLEVU-APIKEY: klevu-1592574318858490' \\\n--header 'Content-Type: application/json' \\\n--header 'Authorization: Bearer YQVmPq63wosB760EAkUNdomeI3Rlm+EFKdg7weXnIFewCCD6eJQJJ5h/w/HdtFpG' \\\n--data '{\n    \"label\": {\n        \"default\": \"Materials\"\n    },\n    \"searchable\": true,\n    \"filterable\": false,\n    \"returnable\": false,\n    \"datatype\": \"MULTIVALUE\"\n}'",
        "customLabel": ""
      }
    ],
    "selectedLanguageId": "xOBGdm4j1d4of8rZLyuHq"
  },
  "results": {
    "languages": [
      {
        "id": "blif1oGwvbqovmU2FClQc",
        "language": "200",
        "customLabel": "",
        "code": "{\n      \"message\": \"Attribute saved successfully.\"\n}"
      }
    ],
    "selectedLanguageId": "blif1oGwvbqovmU2FClQc"
  },
  "request": {
    "pathParameters": [],
    "queryParameters": [],
    "headerParameters": [
      {
        "name": "X-KLEVU-AUTH-ALGO",
        "kind": "required",
        "type": "string",
        "description": "This is the algorithm used to create the security bearer token. ",
        "children": []
      },
      {
        "name": "X-KLEVU-TIMESTAMP",
        "kind": "required",
        "type": "string",
        "description": "This should be your current time while generating the request. It is used to keep the request secured and discourage request relays.",
        "children": []
      },
      {
        "name": "X-KLEVU-APIKEY",
        "kind": "required",
        "type": "string",
        "description": "This is the API Key of your store. Please refer to the Klevu Merchant Centre manual to understand where to get this key from.",
        "children": []
      },
      {
        "name": "Content-Type",
        "kind": "required",
        "type": "string",
        "description": "This needs to be application/JSON as this request body contains a JSON.",
        "children": []
      },
      {
        "name": "Authorization",
        "kind": "required",
        "type": "string",
        "description": "This is the generated security token that authenticates the request.",
        "children": []
      }
    ],
    "bodyDataParameters": [],
    "formDataParameters": []
  },
  "currentNewParameter": {
    "label": "Header Parameter",
    "value": "headerParameters"
  },
  "autoGeneratedAnchorSlug": "add-custom-attribute-materials",
  "legacyHash": "p0coOo0_ENySJVrb1X2eh"
}
```
:::

### A sample batch request

:::BlockQuote
\[
&#x20;   \{
&#x20;       "id": "1",
&#x20;       "type": "KLEVU\_PRODUCT",
&#x20;       "attributes": \{
&#x20;           "name": \{
&#x20;               "default": "Product 1"
&#x20;           },
&#x20;           "brand": "UCB",
&#x20;           "materials": \[
&#x20;               "20% cotton",
&#x20;               "80% polyester"
&#x20;           ]
&#x20;       }
&#x20;   }
]
:::

## Abbreviate

The abbreviations feature allows you to automatically generate shortened forms of values for searchable attributes. This can be useful for improving search relevance and efficiency.

:::hint{type="info"}
By default, the attributes with key "brand" and "manufacturer are abbreviated to enhance search and retrieval efficiency.
:::



The abbreviation logic follows these steps:

1. **Initials Generation**: Each word in the submitted data is abbreviated to its initials.
   - Example: "Larsen & Toubro" becomes "L\&T".
2. **Handling Special Characters**: Special characters like "&" are replaced with no space.
   - Example: "Larsen & Toubro" becomes "LT".

For a given value "Larsen & Toubro", the abbreviations generated are:

- **L\&T**

  : Using initials with special characters preserved.
- **LT**

  : After replacing special characters.

**Example**

:::ApiMethodV2
```json
{
  "name": "Add custom attribute: vendor",
  "method": "PUT",
  "url": "https://indexing-api.ksearchnet.com/v2/attributes/vendor",
  "description": "",
  "tab": "examples",
  "examples": {
    "languages": [
      {
        "id": "xOBGdm4j1d4of8rZLyuHq",
        "language": "json",
        "code": "{\n  \"label\": {\n    \"default\": \"Brand Label\"\n  },\n  \"searchable\": true,\n  \"filterable\": true,\n  \"returnable\": true,\n  \"abbreviate\": true,\n  \"datatype\": \"STRING\"\n}\n",
        "customLabel": "Request Body (JSON)"
      }
    ],
    "selectedLanguageId": "xOBGdm4j1d4of8rZLyuHq"
  },
  "results": {
    "languages": [
      {
        "id": "blif1oGwvbqovmU2FClQc",
        "language": "200",
        "customLabel": "",
        "code": "{\n      \"message\": \"Attribute saved successfully.\"\n}"
      }
    ],
    "selectedLanguageId": "blif1oGwvbqovmU2FClQc"
  },
  "request": {
    "pathParameters": [],
    "queryParameters": [],
    "headerParameters": [
      {
        "name": "X-KLEVU-AUTH-ALGO",
        "kind": "required",
        "type": "string",
        "description": "This is the algorithm used to create the security bearer token. ",
        "children": []
      },
      {
        "name": "X-KLEVU-TIMESTAMP",
        "kind": "required",
        "type": "string",
        "description": "This should be your current time while generating the request. It is used to keep the request secured and discourage request relays.",
        "children": []
      },
      {
        "name": "X-KLEVU-APIKEY",
        "kind": "required",
        "type": "string",
        "description": "This is the API Key of your store. Please refer to the Klevu Merchant Centre manual to understand where to get this key from.",
        "children": []
      },
      {
        "name": "Content-Type",
        "kind": "required",
        "type": "string",
        "description": "This needs to be application/JSON as this request body contains a JSON.",
        "children": []
      }
    ],
    "bodyDataParameters": [],
    "formDataParameters": []
  },
  "currentNewParameter": {
    "label": "Header Parameter",
    "value": "headerParameters"
  },
  "autoGeneratedAnchorSlug": "add-custom-attribute-vendor",
  "legacyHash": "b8J90NqUgq4bhI-dxoH7A"
}
```
:::

## Rangeable

This property enhances search flexibility by allowing users to filter data based on numeric ranges, optimizing search and retrieval operations. It only works with the attributes that are registered as NUMBER or MULTIVALUE\_NUMBER as a data type.

**Example**

:::ApiMethodV2
```json
{
  "name": "Add custom attribute: length",
  "method": "PUT",
  "url": "https://indexing-api.ksearchnet.com/v2/attributes/length",
  "description": "",
  "tab": "examples",
  "examples": {
    "languages": [
      {
        "id": "xOBGdm4j1d4of8rZLyuHq",
        "language": "json",
        "code": "{\n  \"label\": {\n    \"default\": \"Brand Label\"\n  },\n  \"searchable\": true,\n  \"filterable\": true,\n  \"returnable\": true,\n  \"rangeable\": true,\n  \"datatype\": \"NUMBER\"\n}\n",
        "customLabel": "Request Body (JSON)"
      }
    ],
    "selectedLanguageId": "xOBGdm4j1d4of8rZLyuHq"
  },
  "results": {
    "languages": [
      {
        "id": "blif1oGwvbqovmU2FClQc",
        "language": "200",
        "customLabel": "",
        "code": "{\n      \"message\": \"Attribute saved successfully.\"\n}"
      }
    ],
    "selectedLanguageId": "blif1oGwvbqovmU2FClQc"
  },
  "request": {
    "pathParameters": [],
    "queryParameters": [],
    "headerParameters": [
      {
        "name": "X-KLEVU-AUTH-ALGO",
        "kind": "required",
        "type": "string",
        "description": "This is the algorithm used to create the security bearer token. ",
        "children": []
      },
      {
        "name": "X-KLEVU-TIMESTAMP",
        "kind": "required",
        "type": "string",
        "description": "This should be your current time while generating the request. It is used to keep the request secured and discourage request relays.",
        "children": []
      },
      {
        "name": "X-KLEVU-APIKEY",
        "kind": "required",
        "type": "string",
        "description": "This is the API Key of your store. Please refer to the Klevu Merchant Centre manual to understand where to get this key from.",
        "children": []
      },
      {
        "name": "Content-Type",
        "kind": "required",
        "type": "string",
        "description": "This needs to be application/JSON as this request body contains a JSON.",
        "children": []
      }
    ],
    "bodyDataParameters": [],
    "formDataParameters": []
  },
  "currentNewParameter": {
    "label": "Header Parameter",
    "value": "headerParameters"
  },
  "autoGeneratedAnchorSlug": "add-custom-attribute-length",
  "legacyHash": "u9DLTNQWVOwfhp8FunRRu"
}
```
:::

