Skip to content

Create Index API

Edit page

The Create Index API is used to manually create or update an index in Xapiand.

All documents in Xapiand are stored inside of one index or another, indexes are usually dynamically created, but certain settings can only be set for new indexes.

This creates an index named twitter/tweet with all default setting:

PUT /twitter/tweet/

There are several limitations to what you can name your index. The complete list of limitations is:

  • Cannot be . or ..
  • Cannot include \, *, ?, ", <, >, |, (space character), ,, #, :
  • Cannot include / (as part of the name, it’s used for paths)
  • Connot include . (except for the first character)
  • Full path cannot be longer than 243 bytes (note it is bytes, so multi-byte characters will count towards that limit faster)

Indexes can be paths (including / as part of the path).

Each index created can have specific settings associated with it, such can be defined in the body (these can only be set on a new index, so this example uses a fresh one):

PUT /twitter/tweet_sharded/
{
"_settings": {
"number_of_shards": 3,
"number_of_replicas": 2
}
}

The default for number_of_shards is 5, and the default for number_of_replicas is 1 (ie one replica for each primary shard), the above command creates an index with 3 shards and 2 replicas.

The Create Index API also allows to provide a schema, also to be defined in the body:

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

More information about Schemas can be found here.