@@ -511,6 +511,45 @@ Below is a list of all ``box.space`` functions and members.
511
511
**Note re storage engine: ** vinyl supports only the TREE index type, and vinyl
512
512
secondary indexes must be created before tuples are inserted.
513
513
514
+ .. _box_space-path_multikey :
515
+
516
+ **Using the path option with [*] ** The string in a path option can contain '[*]'
517
+ which is called an array index placeholder.
518
+ Indexes defined with this are useful for JSON documents that all have the same structure.
519
+ For example, when creating an index on field#2 for a string document that will start
520
+ with ``{'data': [{'name': '...'}, {'name': '...'}] ``, the parts section in the
521
+ create_index request could look like: ``parts = {{2, 'str', path = 'data[*].name'}} ``.
522
+ Then tuples containing names can be retrieved quickly with ``index_object:select({key-value}) ``.
523
+ In fact a single field can have multiple keys, as in this example which retrieves the
524
+ same tuple twice because there are two keys 'A' and 'B' which both match the request:
525
+
526
+ .. code-block :: none
527
+
528
+ s = box.schema.space.create('json_documents')
529
+ s:create_index('primarykey')
530
+ i = s:create_index('multikey', {parts = {{2, 'str', path = 'data[*].name'}}})
531
+ s:insert({1,
532
+ {data = {{name='A'},
533
+ {name='B'}},
534
+ extra_field = 1}})
535
+ i:select({''},{iterator='GE'})
536
+ -- The result of the select request looks like this:
537
+ -- tarantool> i:select({''},{iterator='GE'})
538
+ -- ---
539
+ -- - - [1, {'data': [{'name': 'A'}, {'name': 'B'}], 'extra_field': 1}]
540
+ -- - [1, {'data': [{'name': 'A'}, {'name': 'B'}], 'extra_field': 1}]
541
+ -- ...
542
+
543
+ Some restrictions exist:
544
+ () '[*]' must be alone or must be at the end of a name in the path;
545
+ () '[*]' must not appear twice in the path;
546
+ () if an index has a path with x[*] then no other index can have a path with x.component;
547
+ () '[*]' must not appear in the path of a primary-key ;
548
+ () if an index has ``unique=true `` and has a path with '[*]' then duplicate keys
549
+ from different tuples are disallowed but duplicate keys for the same tuple are allowed;
550
+ () As with :ref: `Using the path option for map fields <box_space-path >`, the field's value
551
+ must have the structure that the path definition implies, or be nil (nil is not indexed).
552
+
514
553
.. _box_space-delete :
515
554
516
555
.. method :: delete(key)
0 commit comments