Skip to main content
As of December 31, 2023, Shopify no longer allows apps to modify theme code. To integrate Autocomplete and InstantSearch, use the Algolia AI Search & Discovery app’s App Embed and App Blocks. To get started, see Quickstart and Algolia configuration.
The Algolia AI Search & Discovery app can index Shopify metafields. To learn how to add metafields to your products and collections, see Adding metafields in the Shopify documentation. As an alternative, consider using named tags. They let you add extra attributes to your products and variants, without having to configure metafield indexing settings.

How to index metafields

To index Shopify metafields as Algolia searchable attributes, follow these steps:
  1. In your Shopify admin, go to the Algolia AI Search & Discovery app and open the Indexing tab.
  2. Go to the Metafields Indexing section.
  3. Enter a title, namespace, and key for the metafield you want to add. You can find this information in the app you use to manage your metafields.
  4. Optional for products: select Use as facet if you want to use this metafield for faceting or filtering.
  5. Optional: convert the metafield type to a number, a string array, or a JSON-encoded field.
  6. Click Add.
  7. If you’re done adding metafields, click Save.
Add metafields to your index in the Shopify admin

Metafields as facets

For your products, you can select metafields as facets. If you select the Use as facet option when adding or editing a metafield, the metafield is initially inactive. Inactive facets aren’t shown in your index in the Algolia dashboard. To activate the facet, go to the Search Options tab, click InstantSearch - Results page powered by Algolia > Customize and configure your facets.

Type conversion

Metafields dialog in the Shopify admin with an open menu for selecting the type conversion option Shopify supports many types of metafields, but they’re stored as either integer or string types. For your Algolia index, you can convert them to the following types:

Number

Converts strings to:
  • Integers: "100" => 100
  • Decimals: "1.2" => 1.2

String array

Converts a string to an array of strings, split on commas.
  • To include commas in a string, wrap the string in quotes: abc, "def,ghi"
  • To include quotes in a string, wrap the string in quotes and escape the quotes: abc, "def\"ghi"
  • To include backslashes in a string, wrap the string in quotes and escape the backslashes: abc, "def\\ghi"

JSON-encoded

Decode a JSON-encoded string or a JSON metafield. Transform this string:
"[{\"value\":2.0,\"unit\":\"oz\"},{\"value\":3.0,\"unit\":\"oz\"}]"
Into this record:
JSON
[
  { "value": 2.0, "unit": "oz" },
  { "value": 3.0, "unit": "oz" }
]

Schema

The Algolia AI Search & Discovery app adds Shopify metafields to your records as the meta searchableAttributes. For example, a record with three meta fields: colors.main, colors.secondary, and contact.partner.
JSON
{
  "title": "Awesome dress",
  // ... Other attributes
  "meta": {
    "colors": {
      "main": "white",
      "secondary": "gold"
    },
    "contact": {
      "partner": "sellonlineshop.co"
    }
  }
}
You can use any of these metafields in your Algolia index configuration. To select a metafield, use meta.namespace.key, such as meta.colors.primary.

Product and variant metafields

If a variant has metafields, its values override the metafields of its parent product.
Updating a product metafield will trigger a product update webhook but updating a variant-level metafield won’t. Use the Sync with Algolia feature to trigger real-time updates and reflect metafield changes.

Multilingual support

Some Shopify apps that help with translations store their translated data in metafields. The Algolia AI Search & Discovery app can index this translated data. To add support for several languages:
  1. Add the required translated data within metafields associated with the product.
  2. Index those metafields.
  3. Optional: depending on the user’s chosen language, display this data by modifying the relevant product template (InstantSearch and Autocomplete).

Metafield translations with Shopify Markets

By default, when using markets indexing, metafields aren’t translated. Only the following attributes are translated and indexed by default:
  • title
  • handle
  • body_html
  • product_type
To enable metafield translations, contact the Algolia support team. Ensure you’ve indexed metafields and markets. If enabled, metafields are translated and indexed in real-time only.

Constraints

  • Reindexing limitation. Full reindexing erases all metafield translations, which are only restored with real-time updates.
  • Rate limiting. Metafield translations make one API request per field. If you have a large Shopify store, check Shopify’s rate limits.
I