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"
    }
    
    NameTypeDefault valueDescription
    uidStringN/AUnique identifier of the index. Once created, it cannot be changed
    createdAtStringN/ACreation date of the index, represented in RFC 3339 format. Auto-generated on index creation
    updatedAtStringN/ALatest date of index update, represented in RFC 3339 format. Auto-generated on index creation or update
    primaryKeyString / nullnullPrimary 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 parameterDescriptionDefault value
    offsetNumber of indexes to skip0
    limitNumber of indexes to return20

    Response

    NameTypeDescription
    resultsArrayAn array of indexes
    offsetIntegerNumber of indexes skipped
    limitIntegerNumber of indexes returned
    totalIntegerTotal 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

    NameTypeDescription
    index_uid *Stringuid 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

    NameTypeDefault valueDescription
    uid *StringN/Auid of the requested index
    primaryKeyString / nullnullPrimary 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

    NameTypeDescription
    index_uid *Stringuid of the requested index

    Body

    NameTypeDefault valueDescription
    primaryKey *String / nullN/APrimary 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

    NameTypeDescription
    index_uid *Stringuid 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/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 array of objects. Each object has only one key: indexes.

    NameTypeDefault valueDescription
    indexes*Array of stringsN/AArray of the two indexUids to be swapped

    Each indexes array must contain only two elements: the indexUids of the two indexes to be swapped. Sending an empty array ([]) is valid, but no swap operation will be performed.

    NOTE

    You can swap multiple pairs of indexes with a single request. To do so, there must be one object for each pair of indexes to be swapped.

    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.