Search Table

https://{your-workspace-slug}.xata.sh/db/{db_branch_name}/tables/{table_name}/search/

This endpoint performs full text search in a particular table.

Expected Parameters
NameDescriptionInRequiredSchema
db_branch_nameThe DBBranchName matches the pattern `{db_name}:{branch_name}`. pathstring
table_nameThe Table namepathstring

Free Text Search in a Table

POST  https://{your-workspace-slug}.xata.sh/db/{db_branch_name}/tables/{table_name}/search/

Run a free text search operation in a particular table.

The endpoint accepts a query parameter that is used for the free text search and a set of structured filters (via the filter parameter) that are applied before the search. The filter parameter uses the same syntax as the query endpoint with the following exceptions:

  • filters $contains, $startsWith, $endsWith don't work on columns of type text
  • filtering on columns of type multiple is currently unsupported
Request Body Example
{
  "query": "after a long day",
  "filter": {
    "firstName": "Abigail"
  }
}
Request Body Type Definition
/**
 * @example {"query":"after a long day","filter":{"firstName":"Abigail"}}
 */
type SearchTable = {
    /*
     * The query string.
     *
     * @minLength 1
     */
    query: string;
    fuzziness?: FuzzinessExpression;
    prefix?: PrefixExpression;
    filter?: FilterExpression;
    highlight?: HighlightExpression;
    boosters?: BoosterExpression[];
};

/**
 * Maximum [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance) for the search terms. The Levenshtein
 * distance is the number of one charcter changes needed to make two strings equal. The default is 1, meaning that single
 * character typos per word are tollerated by search. You can set it to 0 to remove the typo tollerance or set it to 2 
 * to allow two typos in a word.
 * 
 * @default 1
 * @maximum 2
 * @minimum 0
 */
type FuzzinessExpression = number;

/**
 * If the prefix type is set to "disabled" (the default), the search only matches full words. If the prefix type is set to "phrase", the search will return results that match prefixes of the search phrase.
 */
type PrefixExpression = "phrase" | "disabled";

/**
 * @minProperties 1
 */
type FilterExpression = {
    $exists?: string;
    $existsNot?: string;
    $any?: FilterList;
    $all?: FilterList;
    $none?: FilterList;
    $not?: FilterList;
} & {
    [key: string]: FilterColumn;
};

type HighlightExpression = {
    /*
     * Set to `false` to disable highlighting. By default it is `true`.
     */
    enabled?: boolean;
    /*
     * Set to `false` to disable HTML encoding in highlight snippets. By default it is `true`.
     */
    encodeHTML?: boolean;
};

/**
 * Booster Expression
 */
type BoosterExpression = {
    valueBooster?: ValueBooster;
} | {
    numericBooster?: NumericBooster;
} | {
    dateBooster?: DateBooster;
};

type FilterList = FilterExpression | FilterExpression[];

type FilterColumn = FilterColumnIncludes | FilterPredicate | FilterList;

/**
 * Boost records with a particular value for a column.
 */
type ValueBooster = {
    /*
     * The column in which to look for the value.
     */
    column: string;
    /*
     * The exact value to boost.
     */
    value: string | number | boolean;
    /*
     * The factor with which to multiply the score of the record.
     */
    factor: number;
};

/**
 * Boost records based on the value of a numeric column.
 */
type NumericBooster = {
    /*
     * The column in which to look for the value.
     */
    column: string;
    /*
     * The factor with which to multiply the value of the column before adding it to the item score.
     */
    factor: number;
};

/**
 * Boost records based on the value of a datetime column. It is configured via "origin", "scale", and "decay". The further away from the "origin", 
 * the more the score is decayed. The decay function uses an exponential function. For example if origin is "now", and scale is 10 days and decay is 0.5, it
 * should be interpreted as: a record with a date 10 days before/after origin will score 2 times less than a record with the date at origin.
 */
type DateBooster = {
    /*
     * The column in which to look for the value.
     */
    column: string;
    /*
     * The datetime (formatted as RFC3339) from where to apply the score decay function. The maximum boost will be applied for records with values at this time.
     * If it is not specified, the current date and time is used.
     */
    origin?: string;
    /*
     * The duration at which distance from origin the score is decayed with factor, using an exponential function. It is fromatted as number + units, for example: `5d`, `20m`, `10s`.
     *
     * @pattern ^(\d+)(d|h|m|s|ms)$
     */
    scale: string;
    /*
     * The decay factor to expect at "scale" distance from the "origin".
     */
    decay: number;
};

/**
 * @maxProperties 1
 * @minProperties 1
 */
type FilterColumnIncludes = {
    $includes?: FilterPredicate;
    $includesAny?: FilterPredicate;
    $includesAll?: FilterPredicate;
    $includesNone?: FilterPredicate;
};

type FilterPredicate = FilterValue | FilterPredicate[] | FilterPredicateOp | FilterPredicateRangeOp;

type FilterValue = number | string | boolean;

/**
 * @maxProperties 1
 * @minProperties 1
 */
type FilterPredicateOp = {
    $any?: FilterPredicate[];
    $all?: FilterPredicate[];
    $none?: FilterPredicate | FilterPredicate[];
    $not?: FilterPredicate | FilterPredicate[];
    $is?: FilterValue | FilterValue[];
    $isNot?: FilterValue | FilterValue[];
    $lt?: FilterRangeValue;
    $le?: FilterRangeValue;
    $gt?: FilterRangeValue;
    $ge?: FilterRangeValue;
    $contains?: string;
    $startsWith?: string;
    $endsWith?: string;
    $pattern?: string;
};

/**
 * @maxProperties 2
 * @minProperties 2
 */
type FilterPredicateRangeOp = {
    $lt?: FilterRangeValue;
    $le?: FilterRangeValue;
    $gt?: FilterRangeValue;
    $ge?: FilterRangeValue;
};

type FilterRangeValue = number | string;
Possible Responses
Status CodeDescriptionExample Response/Type Definition
200OK
type SearchTable = {
    records: Record[];
};

/**
 * Xata Table Record Metadata
 */
type Record = RecordMeta & {
    [key: string]: any;
};

/**
 * Xata Table Record Metadata
 */
type RecordMeta = {
    id: RecordID;
    xata: {
        /*
         * The record's version. Can be used for optimistic concurrency control.
         */
        version: number;
        /*
         * The record's table name. APIs that return records from multiple tables will set this field accordingly.
         */
        table?: string;
        /*
         * Highlights of the record. This is used by the search APIs to indicate which fields and parts of the fields have matched the search.
         */
        highlight?: {
            [key: string]: string[] | {
                [key: string]: any;
            };
        };
        /*
         * The record's relevancy score. This is returned by the search APIs.
         */
        score?: number;
        /*
         * Encoding/Decoding errors
         */
        warnings?: string[];
    };
};

/**
 * @pattern [a-zA-Z0-9_-~:]+
 */
type RecordID = string;
400Bad Request
type SearchTable = {
    id?: string;
    message: string;
};
401Authentication Error
{
  "message": "invalid API key"
}
404Example response
type SearchTable = {
    id?: string;
    message: string;
};
5XXUnexpected Error