horizon-docs
horizon-docs copied to clipboard
Schema toml format doesn't describe how to specify indexes
If you create a horizon app using --auto-create-collection and --auto-create-indexes, and then do hz get-schema on it, you will get stuff that looks like:
[collections.test_data]
indexes = ["a","a_b","a_c","a_id","abracadabra","b","field","id_$hz\\_v$","score","time","value_time"]
These index names have a particular format that tells horizon how to create the index when it's passed back to set-schema, but this isn't documented anywhere. We should document it so people are able to specify their indexes without needing to have horizon autogenerate them first.
@Tryneus can probably give us exact details on how the mapping works
Still Uncaught Error: Collection "react_messages" has no index matching ["datetime"]
Example react-chat-app Steps to produce
$ rethinkdb $ cd reactChat $ hz set-schema schema.toml
$ hz get-schema
# This is a TOML document
[collections.react_messages]
indexes = ["datetime"]
[groups.admin]
[groups.admin.rules.carte_blanche]
template = "any()"
$ hz serve --permissions no
Browse localhost:8181 Console message Uncaught Error: Collection "react_messages" has no index matching ["datetime"]
RethinkDB Administration Console r.db('reactChat').table('react_messages_17d5d480f158').info() returned row
{
"db": {
"id": "4348c660-469c-45cb-a4f7-748d25c5a6c1" ,
"name": "reactChat" ,
"type": "DB"
} ,
"doc_count_estimates": [
24
] ,
"id": "6a5a7363-20c7-4646-876e-512c593b988d" ,
"indexes": [
"datetime"
] ,
"name": "react_messages_17d5d480f158" ,
"primary_key": "id" ,
"type": "TABLE"
}
schema.toml file
[collections.react_messages]
indexes = ["datetime"]
config.toml file
bind = [ "localhost" ]
port = 8181
secure = false
project_name = "reactChat"
serve_static = "dist"
auto_create_collection = true
connect = "localhost:28015"
start_rethinkdb = false
debug = true
token_secret = "vpd6iG3Ejfwdo5Fhuv16R3+J6fL69q5skGEkUEgXmb3tYGUy8YMDrwBgrkDeHPX4HKHT5Zrz1KPkhki0R009xA=="
allow_unauthenticated = true
@SenerDemiral This is an issue about documentation. There is a different tracker for issues with Horizon itself. I moved your comment over to there: https://github.com/rethinkdb/horizon/issues/533
The current format is each field in the index, concatenated in order, delimited by underscores. Undescores and backslashes in field names are escaped with backslashes.
Examples:
| index fields | index name |
|---|---|
[ 'a', 'b', 'c' ] |
a_b_c |
[ 'foo_bar', 'baz' ] |
foo\_bar_baz |
[ 'x\y' ] |
x\\y |
There is an open issue to replace the naming scheme with JSON names, which will be a bit more readable and allows nested fields to be indexed: https://github.com/rethinkdb/horizon/issues/444