Index Configuration
IndexConfiguration is a model that enables adding custom values to Elasticsearch. By creating an IndexConfiguration, you can index numeric attribute values on Elasticsearch, allowing them to be used later for different purposes. There are a few points to pay attention to here. Firstly, we expect our attribute value to be numeric or convertible to a numeric value. For example, values like 1, 100, or "50" can be used at this stage. However, if our attribute values contain different non-numeric values such as "30 cm" or "10x20x50," these non-numeric values will not be indexed.
To create an IndexConfiguration object, a sample request should be as follows:
POST
Create an Index Configuration
Path: https://{commerce_url}/api/v1/index-configurations/
Example Request
{
"name": "Index configuration name",
"attribute_key": "exist_attribute_name",
"attribute_type": "integer"
}
We need to include all three fields in the body. The "name" part must match with the existing attribute_key; you cannot pre-add for an attribute that does not exist in the system. The attribute_type value can be integer, float, or long.
If you make a request for a non-existing attribute_key, the response will be as follows:
Example Response
{
"attribute_key": [
"Attribute with key exist_attribute_name \
does not exist"
]
}
Let's assume that we made a successful request with an existing attribute_key
. The response would be as follows:
Example Response
{
"pk": 1,
"name": "Index configuration name",
"attribute_key": "exist_attribute_name",
"attribute_type": "integer"
}
Compatibility of Index Configurations with Facets
After creating Index Configurations, the desired data will be indexed into Elasticsearch. From this point onward, how the data will be utilized is at the discretion of the user.
If we need to share an example and explain how custom usage can be applied concerning the rangability of attribute values, let's assume that we have successfully created an IndexConfiguration object as mentioned above, and there are products created with the attribute_key
used in this object. In this case, we can obtain a rangable facet by creating a new FacetConfiguration object. After creating the IndexConfiguration object, the key used when indexing into Elasticsearch becomes "custom_"
+ indexconfiguration.attribute_key
. For example, if our attribute_key
in the defined object is exist_attribute_name
, the indexed value in Elasticsearch will be custom_exist_attribute_name
. To ensure matching in this context, the attribute_key
of our FacetConfiguration object should be custom_exist_attribute_name
, and we should create a facet for these indexed custom data.
Let's consider that our IndexConfiguration object is created with the following values:
{
"pk": 1,
"name": "Integration Cap Range",
"attribute_key": "integration_cap",
"attribute_type": "integer"
}
The values for the example facet object that we need to create should be defined as follows:
POST
Create a Facet Configuration
Path: https://{commerce_url}/api/v1/facet/
Example Request
{
"pk": 1,
"name": "Facet name",
"attribute_key": "custom_integration_cap",
"attribute_type": "global",
"widget": "multi_select",
"widget_kwargs": {
"labels": {"1000":"1000 +",
"100-1000":"100-1000","0-50":"0-50",
"50-100":"50-100"},
"name": "Cap-Range",
"order": 1
},
"facet": "range",
"facet_kwargs": {
"ranges": [["0-50",[0,49]],["50-100",[50,99]],
["100-1000",[100,999]],["1000",[1000,100000]]]},
"settings": {}
}
With the object created in this way, now the filter can be used for products with the indexed value of custom_integration_cap on the listing page.