@@ -33,18 +33,22 @@ second argument.
33
33
34
34
.. code-block:: ruby
35
35
36
- client[:bands].search_indexes.create_one({ dynamic: true })
37
-
36
+ # Creates indexes on all dynamically indexable fields with a default index name
38
37
client[:bands].search_indexes.create_one(
39
- {
40
- dynamic: false,
41
- fields: {
42
- name: { type: 'string', analyzer: 'lucene.simple' }
43
- }
44
- },
45
- 'band-name-index'
38
+ { mappings: { dynamic: true } }
46
39
)
47
40
41
+ # Creates an index on the specified field with the specified index name
42
+ index_definition = {
43
+ mappings: {
44
+ dynamic: false,
45
+ fields: {
46
+ country: { type: 'string', analyzer: 'lucene.simple' }
47
+ }
48
+ }
49
+ }
50
+ client[:bands].search_indexes.create_one(index_definition, name: 'band-name-index')
51
+
48
52
To create multiple indexes, use ``search_indexes#create_many`` which accepts
49
53
an array of index specifications. Unlike ``create_one``, each index
50
54
specification is a hash with at least a ``definition`` key, which
@@ -53,23 +57,24 @@ the index.
53
57
54
58
.. code-block:: ruby
55
59
56
- client[:bands].search_indexes.create_many([
57
- { definition: { dynamic: true } },
58
- { name: 'band-name-index,
59
- definition: {
60
+ index_spec_1 = { definition: { mappings: { dynamic: true } } }
61
+ index_spec_2 = {
62
+ name: 'band-name-index',
63
+ definition: {
64
+ mappings: {
60
65
dynamic: false,
61
66
fields: {
62
- name : { type: 'string', analyzer: 'lucene.simple' }
67
+ country : { type: 'string', analyzer: 'lucene.simple' }
63
68
}
64
69
}
65
- },
66
- ])
70
+ }
71
+ }
72
+ client[:bands].search_indexes.create_many([index_spec_1, index_spec_2])
67
73
68
74
Note that whether you call ``create_one`` or ``create_many``, the
69
75
method will return immediately, before the indexes are created. The
70
76
indexes are then created in the background, asynchronously.
71
77
72
-
73
78
Update Search Indexes
74
79
=====================
75
80
0 commit comments