Metafields
Algolia supports Shopify’s metafields out of the box. However, there are a few things to note based on the special case that they represent.
Implementing metafields
Our Algolia Shopify plugin does not provide a way for you to create and add metafields. If you want to add metafields to your products you must use a separate application. However, if you have not yet added metafields, we strongly suggest you use our named tags feature instead: like metafields, they allow you to add extra attributes to your products and variants, without negatively affecting the indexing time.
Indexing slowdown
When you start indexing metafields in Algolia, you might notice a slowdown in reindexing speed.
A full reindex that required 1 hour may start taking 4 or 5 hours. This is to be expected.
The reason for this is that Shopify’s API lacks an option to browse a product’s metafields. Therefore, an extra request must be made, per object, and Shopify’s rate-limiting comes into play.
We do an extra API call when you index metafields, which can slow down the process. In that sense, indexing one metafield doesn’t take longer than indexing 20 of them: it’s about whether we need to call the API or not. There isn’t any slowdown for real-time indexing either.
To avoid the reindexing slowdown, you should check out our named tags feature, which allows you to specify extra attributes to your products and variants with tags.
Indexing a metafield
To index a metafield:
-
Head to the Indexing tab of the application.
-
Go to the Metafields indexing section.
-
Click Add.
-
Fill in the namespace, the key, and the name. You can also choose to make it a facet, and do type conversions.
Understand the results
When adding or editing a metafield item, you get a couple of configuration options.
Use as facet (products-only)
To use a product metafield as a facets, tick the Use as facet checkbox and hit save. The metafield then appears in your list of facets.
Type conversion
Metafields in Shopify are limited to integer
and string
types; we can convert them to the following types:
- Number: Convert a string to a
number
. Supports both integers and decimals:"100" => 100
"1.2" => 1.2
- String Array: Convert a string to an array of strings, split on commas.
- If you want to include a comma in a substring, wrap the substring in quotes:
abc, "def,ghi"
- If you want to include a quote in a substring, wrap the substring in quotes and escape the quote:
abc, "def\"ghi"
- If you want to include a backslash in a substring, wrap the substring in quotes and escape the backslash:
abc, "def\\ghi"
- If you want to include a comma in a substring, wrap the substring in quotes:
Schema
When you set up a metafield on an index, it populates the meta
attribute of the record. The namespace is a JSON object nested inside the record.
Below is an example 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 each of these in Algolia’s index settings. To target a metafield, just use meta.namespace.key
.
Product metafields and variant metafields
With respect to indexing, metafields will be treated like other attributes: if present, a variant’s metafield overrides that of its parent product.