Metadata
Metadata helps you store additional information about a document, often referred to as document attributes. It provides added context and enables more refined, targeted searches via powerful filtering, sorting, and faceting capabilities.
Gainly offers you a flexible way to store document metadata in the form of arbitrary key-value pairs (can be nested) with the following limits.
Example
Metadata limits¶
You can add 100 total key-value pairs:
- Key: 50 character limit.
- Value: 500 character limit.
Metadata schema¶
Metadata schema refers to the structured definition of the metadata keys. It defines the key names and data types for the values.
Automatically inferred¶
Gainly automatically infers the data type of a key based on its value the first time the key is submitted. Thus Gainly automatically infers your metadata schema as you add metadata to your documents.
Special Case: Geo-Point Fields
Keys ending in _geo_point
will be inferred as geo_point
fields that accept a geographic point. Thus geo_point
fields are inferred by the key name.
Metadata schema endpoint¶
You can retrieve your automatically-inferred metadata schema using the Metadata Schema endpoint.
Metadata schema in Test vs. Live modes¶
The metadata schema for your Test mode is separate from that of your Live mode. This allows you to test freely without impacting the metadata schema in your live mode.
Best practices¶
-
Define your metadata schema early:
- It's a good practice to define your metadata schema early on so that your team has a consistent structure to work with.
- This should include predefined key names and data types for values.
- Only add metadata to documents in live mode after finalizing your metadata schema.
-
Validate metadata against your schema:
- Always validate metadata against your schema before passing it to the
metadata
parameter in Add document or Update document API requests.
- Always validate metadata against your schema before passing it to the
Cannot modify or delete existing metadata keys¶
To support high-performance searches including filtering, sorting, and faceting - each metadata key is implemented as a field in the semantic index.
To ensure index consistency, the semantic index fields are immutable, meaning you cannot modify (rename or change data type) or delete an existing metadata key.
However you can do the following whenever needed:
- Change the value of a metadata key in a document.
- Add new metadata keys (and their values) to documents.
Professional Services
If modifying or deleting a key is absolutely essential, Gainly Professional Services team can assist you for a fee. Please note this process will involve some downtime for your semantic index.
Supported field types¶
The following field types are supported for keys in your metadata:
String¶
A string sequence of characters. Please note these are not used for text search - but rather used as a part of filter, sort, and facet.
IMPORTANT: Will appear as field type of keyword
String fields will appear as keyword
in your metadata schema, meaning the field is not indexed for full-text search. Instead, it is used for filtering, sorting, and faceting.
In the following example, color
will be inferred as a string and assigned a field type of keyword
:
String fields will appear in metadata schema as shown below:
Date¶
A string in ISO 8601 format, which can include date, time, and timezone.
In the following example, the highlighted fields will be inferred as date
fields:
Integer¶
A whole number (without decimals) that can range from negative to positive values, between -231 and 231 - 1.
In the following example, length
will be inferred as an integer
field:
Float¶
A number that can contain decimals, allowing for both positive and negative values (single precision 32-bit IEEE 754 floating-point value).
In the following example, price
will be inferred as a float
field:
Boolean¶
Accepts true
or false
values. Empty string passed to a boolean field will be treated as false
.
In the following example, is_sale
will be inferred as a boolean
field:
Geo-point¶
A geographic point specified by latitude and longitude coordinates.
IMPORTANT: Use key names ending in _geo_point
Use key names ending in _geo_point
to make sure the key is inferred as a geo-point field. Unlike other field types, geo_point
fields are inferred by their key names.
In the following example, location_geo_point
will be inferred as a geo_point
field:
Arrays¶
Arrays can only store values of one type - such as an array of integers, an array of strings, etc.
In the following example, tags
will be inferred as an array of strings:
Arrays will be represented in the metadata schema by the field type of an individual element within that array:
Objects¶
Objects are standard JSON objects, which can have fields of their own. This means you're able to implement nested fields in your metadata.
In the following example, sale
will be inferred as an object field:
Object fields appear in metadata schema as shown below:
Add metadata¶
You can add metadata to a document using the metadata
parameter in the following endpoints:
Update metadata¶
You can update the metadata for a document using the metadata
parameter of Update Document endpoint. Specifically, you can:
- Add a new key-value pair to a document
- Update the value of an existing key in a document
- Unset an existing key from a document
- Set
metadata
tonull
for a document
However, modifying or deleting an existing key is not supported.
Metadata in queries¶
You can use metadata in your API requests to perform:
While performing these operations, specify your metadata fields using dot notation:
metadata.color
metadata.sale.sale_starts