all repos — litestore @ 98a52155446efe3062f71ef0a0b45a577ad365e6

A minimalist nosql document store.

src/admin/md/api_indexes.md

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
### indexes (LiteStore Indexes)

> %note%
> API v5 Required
> 
> This resource has been introduced in version 5 of the LiteStore API.

LiteStore Indexes are special indexes used to optimize the performance of queries on JSON documents.

> %warning%
> JSON-only Documents Required!
>
> Indexes can be created *only* if the entire database is composed by JSON documents. If not, LiteStore will return an error when attempting to create the first index.

#### OPTIONS indexes

Returns the allowed HTTP verbs for this resource.

##### Example

```
$ curl -i -X OPTIONS http://127.0.0.1:9500/indexes
HTTP/1.1 200 OK
server: LiteStore/1.7.0
access-control-allow-origin: http://localhost:9500
access-control-allow-headers: Content-Type
allow: GET,OPTIONS
access-control-allow-methods: GET,OPTIONS
content-length: 0
```

#### OPTIONS indexes/:id

Returns the allowed HTTP verbs for this resource.

##### Example

```
$ curl -i -X OPTIONS http://127.0.0.1:9500/indexes/name
HTTP/1.1 200 OK
server: LiteStore/1.7.0
access-control-allow-origin: http://localhost:9500
access-control-allow-headers: Content-Type
allow: GET,OPTIONS,PUT,DELETE
access-control-allow-methods: GET,OPTIONS,PUT,DELETE
Content-Length: 0
```

#### GET indexes

Retrieves all indexes and their respective JSON fields.

##### `like` option

If this option is specified, retrieves all indexes matching the specified string. 

> %tip%
> Wildcards
>
> You can use asterisks (\*) as wildcards.

##### `limit` and `offset` options

Provide a way to implement pagination:

* **limit** causes the query to retrieve only the first _n_ results. 
* **offset** causes the query to skip the first _n_ results. 

##### Example

```
$ curl -i http://localhost:9500/indexes/?like=%2Aname%2A
HTTP/1.1 200 OK
server: LiteStore/1.7.0
access-control-allow-origin: http://localhost:9500
content-type: application/json
vary: Origin
access-control-allow-headers: Content-Type
Content-Length: 244

{
  "like": "*name*",
  "total": 2,
  "execution_time": 0.0006140000000000001,
  "results": [
    {
      "id": "name",
      "field": "$.name"
    },
    {
      "id": "document.name",
      "field": "$.document.name"
    }
  ]
}
```

#### GET index/:id

Retrieves the specified index and corresponding JSON field.

##### Example

```
$ curl -i http://localhost:9500/indexes/name
HTTP/1.1 200 OK
server: LiteStore/1.7.0
access-control-allow-origin: http://localhost:9500
content-type: application/json
vary: Origin
access-control-allow-headers: Content-Type
Content-Length: 30

{"id":"name","field":"$.name"}
```

#### PUT indexes/:id

Creates a new index with the specified ID.

> %warning%
> No updates
>
> It is not possible to update an existing index. Delete it and re-create it instead.


##### Example

```
$ curl -i -X PUT -d '{"field": "$.name"}' 'http://127.0.0.1:9500/indexes/name' --header "Content-Type:application/json"
HTTP/1.1 201 Created
Content-Length: 31
Content-Type: application/json
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Origin: http://localhost:9500
Server: LiteStore/1.7.0

{"id":"name", "field":"$.name"}
```

#### DELETE indexes/:id

Deletes the specified index.

##### Example

```
$ curl -i -X DELETE 'http://127.0.0.1:9500/indexes/name'
HTTP/1.1 204 No Content
Content-Length: 0
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Origin: http://localhost:9500
Server: LiteStore/1.7.0
```