Integrations / Shopify

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

The Algolia Shopify plugin doesn’t 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 haven’t yet added metafields, you can use the 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 a metafield

To index a metafield:

  1. Head to the Indexing tab of the application.

  2. Go to the Metafields indexing section.

  3. Click Add.

  4. Fill in the namespace, the key, and the name. You can also choose to make it a facet, and do type conversions.

The products and collections screen in the Shopify admin

Understand the results

When adding or editing a metafield item, you get a couple of configuration options.

Add a metafield screen in the Shopify admin

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; you 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?