Data Indexes¶
Data Indexes - is a additional feature just for convenience.
All data distributed in cluster by partition key, contains several parts :
- 1 -
username
. in hosted mode appserver access to AcapellaDB always give a username - 2 -
keyspace
. keyspace or container created by user in control pannel. Keyspace have access settings . View billing and make a pay. - 3,4,5... - custom user application parts of keyspace
LOGIC
When data changed in keyspace area (any valid accees methods)
_AND_
have flag reindex=true
_AND_
some indexes on keysace are initialized
_THAN_
Data changed and index changed atomicaly (atomicaly depends on transaction write was or is not)
Create the index¶
$ curl 'http://localhost:12000/v2/users/test/keyspaces/foobar/indexes/1' \ -H 'Content-Type: application/json' -XPUT -d '{ "fields": [ {"name": "tag", "type": "string", "order": "ascending"}, {"name": "value", "type": "number", "order": "ascending"} ] }'
where :
test
- usernamefoobar
- keyspaces in which this index will be to work- indexes/
1
- index number / we can to create several indexes for documents in this keyspace "fields"
- list of several fields of this one index? type of it and sort order (composite index)
Read the index list of keyspace¶
$ curl 'http://localhost:12000/v2/users/test/keyspaces/foobar/indexes' {"indexes":{"1":{"fields":[{"name":"tag","type":"string","order": "ascending"},{"name":"value","type":"number","order":"ascending"}]}}}
where :
test
andfoobar
- username and keyspace- return list\dictionary (numbering keys) with index descriptions
Write data to some keyspace and index it in same time¶
$ curl 'http://localhost:12000/v2/kv/partition/test:foobar/clustering/1?reindex=true' \ -XPUT -H 'Content-Type: application/json' -d '{ "tag": "a", "value": 100 }'
$ curl 'http://localhost:12000/v2/kv/partition/test:foobar/clustering/2?reindex=true' \ -XPUT -H 'Content-Type: application/json' -d '{ "tag": "a", "value": 120 }'
$ curl 'http://localhost:12000/v2/kv/partition/test:foobar/clustering/3?reindex=true' \ -XPUT -H 'Content-Type: application/json' -d '{ "tag": "a", "value": 140 }'
$ curl 'http://localhost:12000/v2/kv/partition/test:foobar/clustering/4?reindex=true' \ -XPUT -H 'Content-Type: application/json' -d '{ "tag": "b", "value": 120 }'
$ curl 'http://localhost:12000/v2/kv/partition/test:foobar/clustering/5?reindex=true' \ -XPUT -H 'Content-Type: application/json' -d '{ "tag": "c", "value": 120 }'
Search¶
index search (exact match)¶
$ curl 'http://localhost:12000/v2/kv/partition/test:foobar/index-query' \ -XGET -H 'Content-Type: application/json' -d '{ "query": { "tag": {"eq": "a"}, "value": {"eq": 100} } }' [{"key":["1"],"value":{"tag":"a","value":100.0}}]
index search (exact match) again¶
$ curl 'http://localhost:12000/v2/kv/partition/test:foobar/index-query' \ -XGET -H 'Content-Type: application/json' -d '{ "query": { "tag": {"eq": "b"}, "value": {"eq": 140} } }' [{"key":["4"],"value":{"tag":"b","value":140.0}}]
index search (range)¶
$ curl 'http://localhost:12000/v2/kv/partition/test:foobar/index-query' \ -XGET -H 'Content-Type: application/json' -d '{ "query": { "tag": {"eq": "a"}, "value": {"from": 100} } }' [{"key":["1"],"value":{"tag":"a","value":100.0}}, {"key":["2"], "value":{"tag":"a","value":120.0}}, {"key":["3"],"value":{"tag":"a","value":140.0}}]
index search (range), again¶
$ curl 'http://localhost:12000/v2/kv/partition/test:foobar/index-query' \ -XGET -H 'Content-Type: application/json' -d '{ "query": { "tag": {"eq": "a"}, "value": {"to": 140} } }' [{"key":["1"],"value":{"tag":"a","value":100.0}}, {"key":["2"],"value":{"tag":"a","value":120.0}}]