Allowed metadata types

The Push API allows you to push any primitive type of item metadata (that is, Boolean, number, or string), as well as metadata in the form of arrays of primitives (for example, an array of strings). Object structured types aren’t supported.

Examples of valid metadata values

{
  "is_frequently_updated": false,
  "number_of_likes": 144,
  "average_rating": 85.72,
  "related_product": "Awesome Product",
  "tags": [
    "Relevancy",
    "Machine Learning",
    "Search"
  ]
}

Examples of invalid metadata values

{
  "author_profile": {
    "age": 42,
    "interests": [
      "Literature",
      "Hockey"
    ]
  },
  "table_of_content": [
    [
      "Act:",
      "I - Setup",
      "II - Conflict",
      "III - Resolution"
    ],
    [
      "Page Number:",
      "1",
      "17",
      "39"
    ]
  ]
}

Matching metadata and field types

You should ensure that each metadata you push matches the type of the field (or fields) it populates in your index. The valid field types are:

  • String (for example, "Awesome Product")

  • Array of String (for multi-value fields) (for example, ["Relevancy","Machine Learning","Search"])

  • Integer 32 (for example, 3)

  • Integer 64 (for example, 314159265359)

  • Double (for example, 5.25)

  • Date (see About the Date field type)

  • Vector (for example, [0.235, 0.1234, 0.789, 0.765])

While you can push actual Boolean metadata (as well as arrays of numbers, Booleans, or even many primitive types), you should keep in mind that the Coveo indexing pipeline will attempt to convert such values when it populates their respective fields (see About implicit field type conversion).

Important

You should always map Boolean metadata to String fields.

About the Date field type

The Date field type can be seen as a regular expression that recognizes several standard date and time string patterns:

  • "2002/01/31 11:53:12"

  • "2002-01-31 11:53:12.999Z"

  • "2002-01-31T11:53:12Z"

  • "1 Sep 85 09:54:48 GMT"

  • "12 Sep 85 09:54:48 GMT"

  • "Sun, 06 Nov 1994 08:49:37 GMT"

  • "Sun, 6 Nov 1994 08:49:37 GMT"

  • "Mon, 01-Jan-70 12:00:00 GMT"

  • "Sunday, 06-Nov-94 08:49:37 GMT"

  • "Sunday, 02/17/02 20:01:03 EST"

  • "Sun Nov 27 08:49:37 1994"

  • "Nov 29 2002 7:30PM"

When you push metadata you intend to map to a Date field, you should ensure that your date and time string matches one of the supported patterns. If the target Date field is able to parse your metadata, it will convert it to the corresponding number of milliseconds since Unix epoch.

Note

Although not typically recommended, you can use the dateFormat property when creating or modifying a Date field to specify a single custom date and time string pattern that the field will recognize (see Creating fields).

About implicit field type conversion

A given field can only hold a single type of value. As a result, when the Coveo indexing pipeline populates a field with metadata, it automatically attempts to cast the metadata value (or values) to the appropriate type, if required.

In the following table, each row contains a sample original metadata value along with each resulting field type conversion.

Implicit field type conversions | Coveo

 

Example

You create an isfunny_integer Integer 32 field in your index (see Creating fields). In your Push source, you create a mapping rule to populate this field with the isfunny metadata (see Manage the mapping configuration of a source).

You use the Push API to add or update the following item in your Push source (see Add or update a single item in a Push source):

{
  "isfunny": true,
  "data": "<p>Example...</p>",
  "fileExtension": ".html"
}

When the Coveo indexing pipeline processes this item and applies the mapping rules of your Push source, it implicitly converts the isfunny metadata Boolean value (true) to the corresponding Integer 32 value (0) to populate the isfunny_integer field. Unfortunately, the converted value is meaningless.

A better idea would be to create a isfunny String field. Then, no mapping rule would be necessary, as the Coveo indexing pipeline automatically maps matching metadata and fields. Most importantly, the Boolean metadata value would be converted to the corresponding string value ("true"), which perfectly makes sense.