Skip to content

Explicit Types

Edit page

You know more about your data than Xapiand can guess, so while Dynamic Typing is useful to get started, at some point you will want to specify your own explicit types.

Types are declared inside the _schema object when you create an index (or the first time a field is seen), giving each field a _type:

PUT /test_explicit_types/
{
"_schema": {
"name": {
"_type": "text"
},
"age": {
"_type": "positive"
}
}
}

Once declared, the type is enforced. Documents that fit the schema are indexed as usual:

PUT /test_explicit_types/1
{
"name": "Jane Austen",
"age": 41
}

And the field is queryable with the declared type:

SEARCH /test_explicit_types/
{
"_query": {
"name": "Jane"
}
}

A value that cannot be coerced into the declared type (for instance a negative age for a positive field) is rejected rather than silently reinterpreted.