/*
* Our Javascript client library works on both the client and the browser.
* When using the library on the browser, please be sure to use the
* search-only API Key rather than the master API key since the latter
* has write access to Typesense and you don't want to expose that.
*/letclient=newTypesense.Client({'masterNode':{'host':'master','port':'8108','protocol':'http','apiKey':'<API_KEY>'},'readReplicaNodes':[{'host':'read_replica_1','port':'8108','protocol':'http','apiKey':'<API_KEY>'}],'timeoutSeconds':2})

Definition

Arguments

A list of fields that you wish to index for querying, filtering and faceting.

Apart from specifying the name and type for each field, a field of
type string or string[] can be declared as a faceted field by
setting its facet property to true.

Faceted fields are indexed verbatim without any tokenization or preprocessing.
For example, if you are building a product search, color and brand could be
defined as facet fields.

default_sorting_field

yes

The name of an int32 / float field that determines the order in which
the search results are ranked when a sort_by clause is not provided during searching.
This field must indicate some kind of popularity. For example, in a product search
application, you could define num_reviews field as the default_sorting_field.

Additionally, when a word in a search query matches multiple possible words (either because of a typo or
during a prefix search), this parameter is used to rank such equally matching tokens.
For e.g. both "john" and "joan" are 1-typo away from "jofn". Similarly, in a
prefix search, both "apple" and "apply" would match the prefix "app".

Supported search field types

Typesense allows you to index the following types of fields:

string

int32

int64

float

bool

You can define an array or multi-valued field by suffixing a [] at the end:

string[]

int32[]

int64[]

float[]

bool[]

Index a document

A document to be indexed in a given collection must conform to the schema of the collection.

If the document contains an `id` field of type `string`, Typesense would use that field as the identifier for the
document. Otherwise, Typesense would assign an identifier of its choice to the document.

Definition

Arguments

Use * as the search string to return all documents. This is typically useful when used in
conjunction with filter_by.

For example, to return all documents that match a filter, use: q=*&filter_by=num_employees:10

query_by

yes

One or more string / string[] fields that should be queried against.
Separate multiple fields with a comma: company_name, country

The order of the fields is important: a record that matches on a field earlier in the list is
considered more relevant than a record matched on a field later in the list.
So, in the example above, documents that match on the company_name field are ranked above
documents matched on the country field.

prefix

no

Boolean field to indicate that the last word in the query should be treated as a prefix, and not as a whole
word. This is necessary for building autocomplete and instant search interfaces.

Comma-separated list of fields from the document to include in the search result.

exclude_fields

no

Comma-separated list of fields from the document to exclude in the search result.

drop_tokens_threshold

no

If the number of results found for a specific query is less than this number, Typesense will attempt
to drop the tokens in the query until enough results are found. Tokens that have the least individual hits
are dropped first. Set drop_tokens_threshold to 0 to disable dropping of tokens.

Definition

DELETE ${TYPESENSE_HOST}/collections/:collection

API errors

Typesense API uses standard HTTP response codes to indicate the success or failure of a request.

Codes in the 2xx range indicate success, codes in the 4xx range indicate an error given the information provided
(e.g. a required parameter was omitted), and codes in the 5xx range indicate an error with the Typesense service itself.

Error Code

Meaning

400

Bad Request - The request could not be understood due to malformed syntax.

401

Unauthorized - Your API key is wrong.

404

Not Found - The requested resource is not found.

409

Conflict - When a resource already exists.

422

Unprocessable Entity - Request is well-formed, but cannot be processed.