Mapping Definition Examples

A mapping definition has the following properties:

  • A content array, where each string element (i.e., each rule) must follow the mapping rule syntax (see Mapping Rule Syntax Reference).

    The content array elements of a mapping (its rules) are evaluated sequentially.

    As soon as a rule yields a non-null value, the Coveo Cloud indexing pipeline uses this value to populate the target field, and the sequential evaluation ends.

    This implies that if the first rule of a mapping contains a hardcoded string (e.g., "My string"), this rule will always populate the target field, and none of the subsequent rules will be evaluated.

  • The name of the target field that should be populated with the first non-null value yielded by a rule from the content array. This field must exist in the target Coveo organization index (see Creating Fields).

Mapping a Metadata to a Field of the Same Name

This is the most basic kind of mapping you can define.

{
  "content": [
    "%[product_name]"
  ],
  "field": "product_name"
}

By default, the Coveo Cloud indexing pipeline automatically tries to use incoming Push source item metadata to populate the field whose name matches that of this metadata key.

This means that in a Push source, you never need to explicitly define mapping rules where the incoming metadata key and target field names are identical.

This also implies that each metadata you want this default mapping behavior to apply to in a Push source must have a field of the same name in the target Coveo organization index (see Creating Fields).

See About Push Source Item Metadata.

Mapping a Metadata to a Field with a Different Name

You may want to map metadata and fields whose names differ.

A common use case for this is when your index contains a field whose name is prefixed for a certain source, but whose purpose is identical to that of the corresponding un-prefixed standard field (e.g., the mysource_date field could serve the same purpose as the date field, but be specific to the mysource source).

{
  "content": [
    "%[author]"
  ],
  "field": "mysource_author"
}

Mapping a Concatenated String to a Field

The mapping rule syntax allows you to combine many metadata references and hardcoded strings into a single mapping rule. When such a rule applies, its target field is populated by the resulting concatenated string.

{
  "content": [
    "%[civic_number], %[street_name]"
  ],
  "field": "address"
}

Defining Several Alternative Mapping Rules for a Field

When a certain mapping includes more than one rule, those rules are evaluated sequentially.

In this example, the rating field may be populated by one of three distinct rules, depending on what metadata is available when an item passes through the Coveo Cloud indexing pipeline:

  • If the item has an internal_rating metadata value, this value populates the field.
  • Otherwise, if the item has an external_rating metadata value, this value populates the field.
  • Finally, if all else fails, the "No rating" hardcoded string populates the field.
{
  "content": [
   "%[internal_rating]",
   "%[external_rating]",
   "No rating"
  ],
  "field": "rating"
}
What's Next for Me?