--- title: Mapping definition examples slug: '66' canonical_url: https://docs.coveo.com/en/66/ collection: index-content source_format: adoc --- # Mapping definition examples A [mapping](https://docs.coveo.com/en/217/) definition has the following properties: * A `content` array, where each string element (that is, each _rule_) must follow the [mapping rule syntax](https://docs.coveo.com/en/1839/). > **Important** > > The `content` array elements of a mapping (its rules) are evaluated sequentially. > > As soon as a rule yields a non-null value, the [Coveo indexing pipeline](https://docs.coveo.com/en/184/) uses this value to populate the target [field](https://docs.coveo.com/en/200/), and the sequential evaluation ends. > > This implies that if the first rule of a mapping contains a hardcoded string (for example, `"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](https://docs.coveo.com/en/185/) [index](https://docs.coveo.com/en/204/). See [Create fields with the API](https://docs.coveo.com/en/144/) for details on field creation. ## Mapping a metadata to a field of the same name This is the most basic kind of [mapping](https://docs.coveo.com/en/217/) you can define. ```json { "content": [ "%[product_name]" ], "field": "product_name" } ``` > **Note** > > By default, the Coveo indexing pipeline automatically tries to use incoming Push [source](https://docs.coveo.com/en/246/) [item](https://docs.coveo.com/en/210/) [metadata](https://docs.coveo.com/en/218/) to populate the [field](https://docs.coveo.com/en/200/) 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 [index](https://docs.coveo.com/en/204/). > See [Create fields with the API](https://docs.coveo.com/en/144/) for details on field creation. > > See [About Push Source Item Metadata](https://docs.coveo.com/en/115/). ## Mapping a metadata to a field with a different name You may want to [map](https://docs.coveo.com/en/217/) [metadata](https://docs.coveo.com/en/218/) and [field](https://docs.coveo.com/en/200/) whose names differ. A common use case for this is when your [index](https://docs.coveo.com/en/204/) contains a field whose name is prefixed for a certain [source](https://docs.coveo.com/en/246/), but whose purpose is identical to that of the corresponding un-prefixed standard field. For example, the `mysource_date` field could serve the same purpose as the `date` field, but be specific to the `mysource` source. ```json { "content": [ "%[author]" ], "field": "mysource_author" } ``` ## Mapping a concatenated string to a field The [mapping](https://docs.coveo.com/en/217/) rule syntax allows you to combine many [metadata](https://docs.coveo.com/en/218/) references and hardcoded strings into a single mapping rule. When such a rule applies, its target [field](https://docs.coveo.com/en/200/) is populated by the resulting concatenated string. ```json { "content": [ "%[civic_number], %[street_name]" ], "field": "address" } ``` ## Defining several alternative mapping rules for a field When a certain [mapping](https://docs.coveo.com/en/217/) includes more than one rule, those rules are evaluated sequentially. In this example, the `rating` [field](https://docs.coveo.com/en/200/) may be populated by one of three distinct rules, depending on what [metadata](https://docs.coveo.com/en/218/) is available when an [item](https://docs.coveo.com/en/210/) passes through the [Coveo indexing pipeline](https://docs.coveo.com/en/184/): * 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. ```json { "content": [ "%[internal_rating]", "%[external_rating]", "No rating" ], "field": "rating" } ```