# Indexes

The /indexes route allows you to create, manage, and delete your indexes.

Learn more about indexes.

# Index object

{
  "uid": "movies",
  "createdAt": "2022-02-10T07:45:15.628261Z",
  "updatedAt": "2022-02-21T15:28:43.496574Z",
  "primaryKey": "id"
}
Name Type Default value Description
uid String N/A Unique identifier of the index. Once created, it cannot be changed
createdAt String N/A Creation date of the index, represented in RFC 3339 (opens new window) format. Auto-generated on index creation
updatedAt String N/A Latest date of index update, represented in RFC 3339 (opens new window) format. Auto-generated on index creation or update
primaryKey String / null null Primary key of the index. If not specified, Meilisearch guesses your primary key from the first document you add to the index

# List all indexes

GET
/indexes

List all indexes. Results can be paginated by using the offset and limit query parameters.

# Query parameters

Query parameter Description Default value
offset Number of indexes to skip 0
limit Number of indexes to return 20

# Response

Name Type Description
results Array An array of indexes
offset Integer Number of indexes skipped
limit Integer Number of indexes returned
total Integer Total number of indexes

# Example

curl \
  -X GET 'http://localhost:7700/indexes?limit=3'

# Response: 200 Ok

{
  "results": [
    {
      "uid": "books",
      "createdAt": "2022-03-08T10:00:27.377346Z",
      "updatedAt": "2022-03-08T10:00:27.391209Z",
      "primaryKey": "id"
    },
    {
      "uid": "meteorites",
      "createdAt": "2022-03-08T10:00:44.518768Z",
      "updatedAt": "2022-03-08T10:00:44.582083Z",
      "primaryKey": "id"
    },
    {
      "uid": "movies",
      "createdAt": "2022-02-10T07:45:15.628261Z",
      "updatedAt": "2022-02-21T15:28:43.496574Z",
      "primaryKey": "id"
    }
  ],
  "offset": 0,
  "limit": 3,
  "total": 5
}  

# Get one index

GET
/indexes/{index_uid}

Get information about an index.

# Path parameters

Name Type Description
index_uid * String uid of the requested index

# Example

curl \
  -X GET 'http://localhost:7700/indexes/movies'

# Response: 200 Ok

{
  "uid": "movies",
  "createdAt": "2022-02-10T07:45:15.628261Z",
  "updatedAt": "2022-02-21T15:28:43.496574Z",
  "primaryKey": "id"
}

# Create an index

POST
/indexes

Create an index.

# Body

Name Type Default value Description
uid * String N/A uid of the requested index
primaryKey String / null null Primary key of the requested index
{
  "uid": "movies",
  "primaryKey": "id"
}

# Example

curl \
  -X POST 'http://localhost:7700/indexes' \
  -H 'Content-Type: application/json' \
  --data-binary '{
    "uid": "movies",
    "primaryKey": "id"
  }'

# Response: 202 Accepted

{
  "taskUid": 0,
  "indexUid": "movies",
  "status": "enqueued",
  "type": "indexCreation",
  "enqueuedAt": "2021-08-12T10:00:00.000000Z"
}

You can use the response's taskUid to track the status of your request.

# Update an index

PATCH
/indexes/{index_uid}

Update an index's primary key. You can freely update the primary key of an index as long as it contains no documents.

To change the primary key of an index that already contains documents, you must first delete all documents in that index. You may then change the primary key and index your dataset again.

NOTE

It is not possible to change an index's uid.

# Path parameters

Name Type Description
index_uid * String uid of the requested index

# Body

Name Type Default value Description
primaryKey * String / null N/A Primary key of the requested index

# Example

curl \
  -X PATCH 'http://localhost:7700/indexes/movies' \
  -H 'Content-Type: application/json' \
  --data-binary '{ "primaryKey": "id" }'

# Response: 202 Accepted

{
  "taskUid": 1,
  "indexUid": "movies",
  "status": "enqueued",
  "type": "indexUpdate",
  "enqueuedAt": "2021-08-12T10:00:00.000000Z"
}

You can use the response's taskUid to track the status of your request.

# Delete an index

DELETE
/indexes/{index_uid}

Delete an index.

# Path parameters

Name Type Description
index_uid * String uid of the requested index

# Example

curl \
  -X DELETE 'http://localhost:7700/indexes/movies'

# Response: 202 Accepted

{
  "taskUid": 1,
  "indexUid": "movies",
  "status": "enqueued",
  "type": "indexDeletion",
  "enqueuedAt": "2021-08-12T10:00:00.000000Z"
}

You can use the response's taskUid to track the status of your request.

# Swap indexes

POST
/indexes/swap-indexes

Swap the documents, settings, and task history of two or more indexes. You can only swap indexes in pairs. However, a single request can swap as many index pairs as you wish.

Swapping indexes is an atomic transaction: either all indexes are successfully swapped, or none are.

Swapping indexA and indexB will also replace every mention of indexA by indexB and vice-versa in the task history. enqueued tasks are left unmodified.

To learn more about index swapping, refer to this short guide.

# Body

An object containing some string arrays, each called indexes.

Name Type Default value Description
indexes* Array of strings N/A Array of the two indexUids to be swapped

NOTE

You can send multiple indexes arrays in a single request. Each indexes array should contain only two elements: the indexUids of the two indexes to be swapped.

Sending [] is valid but no swap operation will be performed.

# Example

curl \
  -X POST 'http://localhost:7700/swap-indexes' \
  -H 'Content-Type: application/json' \
  --data-binary '[
    {
      "indexes": [
        "indexA",
        "indexB"
      ]
    },
    {
      "indexes": [
        "indexX",
        "indexY"
      ]
    }
  ]'

# Response

{
  "taskUid": 3,
  "indexUid": null,
  "status": "enqueued",
  "type": "indexSwap",
  "enqueuedAt": "2021-08-12T10:00:00.000000Z"
}

NOTE

Since indexSwap is a global task, the indexUid is always null.

You can use the response's taskUid to track the status of your request.