Metafields
From December 31, 2023, Algolia’s Search and Discovery application can’t modify the coding of Shopify themes. For more information, refer to Shopify’s Asset API documentation. As an alternative, Algolia offers Shopify’s App Embed and App Blocks features for Autocomplete and InstantSearch interfaces. For more information, refer to the Quick start and Shopify Algolia configuration documentation.
Algolia supports indexing Shopify’s metafields.
To learn how to add metafields to your products and collections, see Adding metafields in the Shopify documentation.
As an alternative, consider using named tags. They let you add extra attributes to your products and variants, without increasing the indexing time.
Index metafields
- In your Shopify admin, go to the Algolia Search and Discovery app.
- Open the Indexing tab.
- Go to the Metafields Indexing section.
- Enter a title, namespace, and key for the metafield you want to add. You should be able to find this information in the app you use to manage your metafields.
- Optional (only for products): select Use as facet if you want to use this metafield for faceting or filtering.
- Optional: convert the type of the metafield to a number, a string array, or a JSON encoded field.
- Click Add. If you’re done adding metafields, click Save.
Metafields as facets
For your products, you can select metafields as facets. If you select the Use as facet option when adding or editing a metafield, the metafield is inactive at first. Inactive facets aren’t shown in your index in the Algolia dashboard.
To activate the facet, go to the Search Options tab, click InstantSearch - Results page powered by Algolia > Customize and configure your facets
Type conversion
Shopify metafields can only be integer
or string
types.
For your Algolia index, you can convert them to the following types:
Number
Converts strings to:
- Integers:
"100" => 100
- Decimals:
"1.2" => 1.2
String array
Converts a string to an array of strings, split on commas.
- To include commas in a string, wrap the string in quotes:
abc, "def,ghi"
- To include quotes in a string, wrap the string in quotes and escape the quotes:
abc, "def\"ghi"
- To include backslashes in a string, wrap the string in quotes and escape the backslashes:
abc, "def\\ghi"
JSON Encoded
Decode a JSON-encoded string.
Transform this string:
1
"[{\"value\":2.0,\"unit\":\"oz\"},{\"value\":3.0,\"unit\":\"oz\"}]"
Into this record:
1
2
3
4
[
{ "value": 2.0, "unit": "oz" },
{ "value": 3.0, "unit": "oz" }
]
Schema
In your Algolia index, metafields are added to your records as meta
attribute,
which itself is also a (nested) JSON object.
For example, a record with three metafields colors.main
, colors.secondary
, and contact.partner
:
1
2
3
4
5
6
7
8
9
10
11
12
13
{
"title": "Awesome dress",
// ... Other attributes
"meta": {
"colors": {
"main": "white",
"secondary": "gold"
},
"contact": {
"partner": "sellonlineshop.co"
}
}
}
You can use any of these metafields in your Algolia index configuration.
To select a metafield, use meta.namespace.key
, such as meta.colors.primary
.
Product and variant metafields
If a variant has metafields, their values override the metafields of its parent product.