Integrations / Platforms / Shopify / Metafields
Jun. 24, 2019

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 indexing 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.

There will be no slowdown difference between indexing 1 or 20 metafields: the extra API call is a question of having metafields versus not having metafields.

To avoid an indexing 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:

1. Head to the Indexing tab of the application.

2. Go to the Products or Collections section and click Manage metafields.

The products and collections screen in the Shopify admin

3. Click Add a metafield.

4. Fill in the namespace, the key, and the name you want to give it.

Add a metafield screen in the Shopify admin

Understand the results

If you click Edit on a metafield item, you’ll be given a couple of configuration options.

The metafield configuration options

Use as facet (products-only)

To use a product metafield as a facets, tick the relevant checkbox, hit save, and reload the page. The metafield will then appear 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"

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.

Did you find this page helpful?