Creating secondary indexes
You can add new secondary indexes by defining the map and reduce functions to retrieve the specific data from Cloudant databases.
To create a secondary index, complete the following steps:
About this task
- From the main menu, to open the Select a wizard page of the New wizard, select .
- To open the Create Cloudant Index wizard, expand the Repository node, select Cloudant Index and click Next.
- From the Data source list, select a Cloudant data source to which you want to add a new index.
- From the Design document list, select the design document in which you want to include the new index.
- In the Index name field, enter the name that you want to use for the index.
- To create the index and open it in the Cloudant Secondary Index editor, from the Index type list, select Secondary Index and click Finish.
- In the Map function field, specify the map function that retrieves keys and values from the documents based on the content of each document.
From the Reduce list, select a reduce function that
you want to use to aggregate the data.
- Select None, if you do not want to apply any reduce function.
- Select _sum to return the sum of all values for a key.
- Select _count to return the count of the rows for a key.
- Select _stats to return the JSON structure that contains sum, count, min, max, and sum squared.
- Select Custom Reduce Function to specify your own reduce function in the Custom reduce function field.
- To save the secondary index that you created to the database, click Save.
The secondary index that you created is added to the Secondary Indexes folder under the appropriate design document node in the Repository Explorer view.