|
| 1 | +.. _mcli-atlas-search-index-create-command: |
| 2 | + |
| 3 | +=========================================== |
| 4 | +mongocli atlas cluster searach index create |
| 5 | +=========================================== |
| 6 | + |
| 7 | +.. default-domain:: mongodb |
| 8 | + |
| 9 | +.. contents:: On this page |
| 10 | + :local: |
| 11 | + :backlinks: none |
| 12 | + :depth: 1 |
| 13 | + :class: singlecol |
| 14 | + |
| 15 | +The ``search index create`` command creates an |fts| :atlas:`index |
| 16 | +</reference/atlas-search/index-definitions/>`. You can also create an |
| 17 | +|fts| :atlas:`index </reference/atlas-search/index-management/>` through |
| 18 | +the |service| :atlas:`UI </reference/atlas-search/create-index/>` or |
| 19 | +:atlas:`API </reference/api/fts-indexes-create-one/>`. |
| 20 | + |
| 21 | +.. _mcli-atlas-search-index-create-syntax: |
| 22 | + |
| 23 | +Syntax |
| 24 | +------ |
| 25 | + |
| 26 | +.. code-block:: text |
| 27 | + |
| 28 | + mongocli atlas cluster search|fts index create <index-name> |
| 29 | + --clusterName <cluster-name> |
| 30 | + --collection <collection-name> |
| 31 | + --db <database-name> |
| 32 | + [ --dynamic ] |
| 33 | + [ --field <field-name>:<index-type> ] |
| 34 | + [ --profile|-P <profile-name> ] |
| 35 | + [ --projectId <project-ID> ] |
| 36 | + [ --searchAnalyzer <analyzer-name> ] |
| 37 | + |
| 38 | +.. _mcli-atlas-search-index-create-options: |
| 39 | + |
| 40 | +Options |
| 41 | +------- |
| 42 | + |
| 43 | +.. list-table:: |
| 44 | + :header-rows: 1 |
| 45 | + :widths: 20 10 60 10 |
| 46 | + |
| 47 | + * - Option |
| 48 | + - Type |
| 49 | + - Description |
| 50 | + - Required? |
| 51 | + |
| 52 | + * - ``<index-name>`` |
| 53 | + - string |
| 54 | + - Name of the |fts| index. |
| 55 | + - yes |
| 56 | + |
| 57 | + * - ``--clusterName`` |
| 58 | + - string |
| 59 | + - Name of the cluster. |
| 60 | + - yes |
| 61 | + |
| 62 | + * - ``--collection`` |
| 63 | + - string |
| 64 | + - Name of the collection for which to create an |fts| index. |
| 65 | + - yes |
| 66 | + |
| 67 | + * - ``--db`` |
| 68 | + - string |
| 69 | + - Name of the database that contains the collection. |
| 70 | + - yes |
| 71 | + |
| 72 | + * - ``--dynamic`` |
| 73 | + - flag |
| 74 | + - Whether the |fts| index uses dynamic field mappings. This is |
| 75 | + required if ``field`` is not specified. You cannot specify |
| 76 | + ``field`` if this flag is set. |
| 77 | + |
| 78 | + To learn more, see :atlas:`Static and Dynamic Mappings |
| 79 | + <reference/atlas-search/index-definitions/#static-and-dynamic-mappings>`. |
| 80 | + - no |
| 81 | + |
| 82 | + * - ``--field`` |
| 83 | + - string |
| 84 | + - Comma-separated list of fields to index in the following format: |
| 85 | + |
| 86 | + .. code-block:: text |
| 87 | + :copyable: false |
| 88 | + |
| 89 | + <field-name>:<index-type> |
| 90 | + |
| 91 | + where: |
| 92 | + |
| 93 | + - ``<field-name>`` is the name of the field to index. |
| 94 | + - ``<index-type>`` is the :atlas:`type |
| 95 | + </reference/atlas-search/index-definitions/#data-types/>` of index. |
| 96 | + Value can be one of the following: ``autocomplete``, ``boolean``, |
| 97 | + ``date``, ``document``, ``geo``, ``number``, ``objectId``, ``string``. |
| 98 | + |
| 99 | + This is required if the index uses static mappings. You cannot set the |
| 100 | + ``dynamic`` flag if field names are specified. |
| 101 | + - no |
| 102 | + |
| 103 | + * - ``--profile``, ``-P`` |
| 104 | + - string |
| 105 | + - Name of the profile where the public and private keys for the project |
| 106 | + are set. If omitted, uses the {+default-profile+}. To learn more about |
| 107 | + creating a profile, see :ref:`mcli-configure`. |
| 108 | + - no |
| 109 | + |
| 110 | + * - ``--projectId`` |
| 111 | + - string |
| 112 | + - Unique identifier of the project where you want to create the cluster. |
| 113 | + If omitted, uses the project ID in the profile or :ref:`environment |
| 114 | + variable <mcli-env-var>`. |
| 115 | + - no |
| 116 | + |
| 117 | + * - ``--searchAnalyzer`` |
| 118 | + - string |
| 119 | + - Analyzer to use when searching the index. Value can be one of the |
| 120 | + following: |
| 121 | + |
| 122 | + - :atlas:`lucene.standard </reference/atlas-search/analyzers/standard/>` |
| 123 | + - :atlas:`lucene.simple </reference/atlas-search/analyzers/simple/>` |
| 124 | + - :atlas:`lucene.whitespace |
| 125 | + </reference/atlas-search/analyzers/whitespace/>` |
| 126 | + - :atlas:`lucene.language </reference/atlas-search/analyzers/language/>` |
| 127 | + - :atlas:`lucene.keyword </reference/atlas-search/analyzers/keyword/>` |
| 128 | + |
| 129 | + If omitted, defaults to ``lucene.standard``. |
| 130 | + - no |
| 131 | + |
| 132 | +.. _mcli-atlas-search-index-create-output: |
| 133 | + |
| 134 | +Output |
| 135 | +------ |
| 136 | + |
| 137 | +.. include:: /includes/command-output-intro.rst |
| 138 | + |
| 139 | +.. include:: /includes/atlas-search-index-output-fields.rst |
| 140 | + |
| 141 | +.. _mcli-atlas-search-index-create-egs: |
| 142 | + |
| 143 | +Examples |
| 144 | +-------- |
| 145 | + |
| 146 | +The following examples use the ``mongocli atlas cluster search index create`` |
| 147 | +command to create an |fts| index named ``default`` on the |
| 148 | +``sample_mflix.movies`` collection in an |service| cluster named |
| 149 | +``myTestCluster``. |
| 150 | + |
| 151 | +Create an Index for Dynamic Field Mappings |
| 152 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 153 | + |
| 154 | +The following ``mongocli atlas cluster search index create`` command creates |
| 155 | +an |fts| index that uses dynamic field mappings. It uses the ``egAtlasProfile`` |
| 156 | +to access the project. |
| 157 | + |
| 158 | +.. code-block:: text |
| 159 | + |
| 160 | + mongocli atlas cluster search index create default --dynamic --clusterName myTestCluster --db sample_mflix --collection movies --profile egAtlasProfile |
| 161 | + |
| 162 | +The previous command prints the following fields in |json| format to the |
| 163 | +terminal. To learn more about these fields, see |
| 164 | +:ref:`mcli-atlas-search-index-create-output`. |
| 165 | + |
| 166 | +.. code-block:: json |
| 167 | + :copyable: false |
| 168 | + |
| 169 | + { |
| 170 | + "analyzer": "lucene.standard", |
| 171 | + "collectionName": "movies", |
| 172 | + "database": "sample_mflix", |
| 173 | + "indexID": "5f1f40842f2ac35f49190c20", |
| 174 | + "mappings": { |
| 175 | + "dynamic": true |
| 176 | + }, |
| 177 | + "name": "dynamic", |
| 178 | + "searchAnalyzer": "lucene.standard" |
| 179 | + } |
| 180 | + |
| 181 | +Create an Index for Specific Fields |
| 182 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 183 | + |
| 184 | +The following ``mongocli atlas cluster search index create`` command creates |
| 185 | +an |fts| index that indexes the ``title`` field of type ``string`` using the |
| 186 | +``keyword`` analyzer and ``plot`` field of type ``string`` using the |
| 187 | +``keyword`` analyzer. It uses the {+default-profile+} to access the project. |
| 188 | + |
| 189 | +.. code-block:: text |
| 190 | + |
| 191 | + mongocli atlas cluster search index create default --clusterName myTestCluster --db sample_mflix --collection movies --field title:string,released:date |
| 192 | + |
| 193 | +The previous command prints the following fields in |json| format to the |
| 194 | +terminal. To learn more about these fields, see |
| 195 | +:ref:`mcli-atlas-search-index-create-output`. |
| 196 | + |
| 197 | +.. code-block:: json |
| 198 | + :copyable: false |
| 199 | + |
| 200 | + { |
| 201 | + "analyzer": "lucene.standard", |
| 202 | + "collectionName": "movies", |
| 203 | + "database": "sample_mflix", |
| 204 | + "indexID": "5f2099cd683fc55fbb30bef6", |
| 205 | + "mappings": { |
| 206 | + "dynamic": false, |
| 207 | + "fields": { |
| 208 | + "released": { |
| 209 | + "type": "date" |
| 210 | + }, |
| 211 | + "title": { |
| 212 | + "type": "string" |
| 213 | + } |
| 214 | + } |
| 215 | + }, |
| 216 | + "name": "default", |
| 217 | + "searchAnalyzer": "lucene.standard" |
| 218 | + } |
0 commit comments