Create an index
List indices -
You can list all your indices along with their associated information (number of entries, disk size, etc.) with the
var result = client.ListIndexes(); // Asynchronous // var result = await client.ListIndexesAsync(); System.Diagnostics.Debug.WriteLine(res);
Delete an index -
You can delete an index using its name:
client.DeleteIndex("contacts"); // Asynchronous // await client.DeleteIndexAsync("contacts");
Clear an index -
You can delete the index contents without removing settings and index specific API keys by using the
index.ClearIndex(); // Asynchronous // await index.ClearIndexAsync();
Copy index -
You can copy an existing index using the
Warning: The copy command will overwrite the destination index.
// Copy MyIndex in MyIndexCopy client.CopyIndex("MyIndex", "MyIndexCopy"); // Asynchronous await client.CopyIndexAsync("MyIndex", "MyIndexCopy");
Move index -
In some cases, you may want to totally reindex all your data. In order to keep your existing service running while re-importing your data we recommend the usage of a temporary index plus an atomical move using the
// Rename MyTmpIndex to MyIndex (and overwrite it) client.MoveIndex("MyTmpIndex", "MyIndex"); // Asynchronous // await client.MoveIndexAsync("MyTmpIndex", "MyIndex");
The MoveIndex method overrides the destination index, and deletes the temporary one. In other words, there is no need to call the
deleteIndex methods to clean the temporary index. It also overrides all the settings of the destination index (except the
replicas parameter that need to not be part of the temporary index settings).
Recommended steps If you want to fully update your index
MyIndex every night, we recommend the following process:
- Get settings and synonyms from the old index using Get settings and Get synonym.
- Apply settings and synonyms to the temporary index
MyTmpIndex, (this will create the
MyTmpIndexindex) using Set settings and Batch synonyms ([!] Make sure to remove the
replicasparameter from the settings if it exists.
- Import your records into a new index using Add Objects).
- Atomically replace the index
MyIndexwith the content and settings of the index
MyTmpIndexusing the Move index method. This will automatically override the old index without any downtime on the search.
You’ll end up with only one index called
MyIndex, that contains the records and settings pushed to
MyTmpIndex and the replica-indices that were initially attached to
MyIndex will be in sync with the new data.
Did you find this page helpful?
We're always looking for advice to help improve our documentation!
Please let us know what's working (or what's not!).
We're constantly iterating thanks to the feedback we receive.