🎉 Try the public beta of the new docs site at algolia.com/doc-beta! 🎉
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 Search and Discovery app 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 app. However, if you haven’t yet added metafields, you can use the named tags feature instead: like metafields, they let you 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 app.

  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.
    • To include a comma in a string, wrap the string in quotes: abc, "def,ghi"
    • To include a quote in a string, wrap the string in quotes and escape the quote: abc, "def\"ghi"
    • To include a backslash in a string, wrap the string in quotes and escape the backslash: abc, "def\\ghi"
  • JSON Encoded: Decode a JSON-encoded string.
    • "[{\"value\":2.0,\"unit\":\"oz\"},{\"value\":3.0,\"unit\":\"oz\"}]" becomes the following object in your record.
1
2
3
4
    [
      {"value":2.0,"unit":"oz"},
      {"value":3.0,"unit":"oz"}
    ]

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?