for

Metafields

The special case of 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.

Indexing slowdown

When you start indexing metafields in Algolia, you might notice a slowdown in indexing speed.
A full reindex that used to take 1 hour jumping to 4 or 5 hours is to be expected.

The reason for this is the lack of an option to browse all items with their metafields included using Shopify's API. We need to do an extra request per object and Shopify's rate-limiting comes into play.

There will be no difference between indexing 1 or 20 metafields though.

To avoid the indexing slowdown, you should first check out our Named Tags feature which allows you to specify extra attributes to your Products and Variants by solely using tags.

Indexing a metafield

Indexing a metafield is really easy:

  • head to the Indexing tab of the application
  • click Manage metafields under the Products or Collections section
Metafield form screenshot
  • click Add a metafield
  • fill its namespace, key, and the name you want to give it
Metafield form screenshot

Metafield options

If you click Edit on a Metafield line, you'll be given a few configuration options.

Metafield options screenshot

Use as facet (products-only)

For products, you might want to use a metafield as a facet.
Simply tick the checkbox, Confirm, Save and reload to see it in the list of facets in the Search options tab.

Type conversion

Since Metafields in Shopify are limited to integer and string types, we can optionally convert them for you. Here are the types that we support:

  • 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, splitted 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 will populate the meta attribute of the record.
The namespace will become a JSON object inside the record.

Here is an example with three metafields: colors.main, colors.secondary and contact.partner.

{
  "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

As explained in the Product schema description, we're actually indexing product variants.
For a specific variant, we'll take the metafield if present on the variant, otherwise fallback on the same metafield on the related product.