Creating secondary indexes

You can add new secondary indexes by defining the map and reduce functions to retrieve the specific data from Cloudant databases.

About this task

To create a secondary index, complete the following steps:


  1. From the main menu, to open the Select a wizard page of the New wizard, select File > New > Other.
  2. To open the Create Cloudant Index wizard, expand the Repository node, select Cloudant Index and click Next.
  3. From the Data source list, select a Cloudant data source to which you want to add a new index.
  4. From the Design document list, select the design document in which you want to include the new index.
  5. In the Index name field, enter the name that you want to use for the index.
  6. To create the index and open it in the Cloudant Secondary Index editor, from the Index type list, select Secondary Index and click Finish.
  7. In the Map function field, specify the map function that retrieves keys and values from the documents based on the content of each document.
  8. 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.
  9. 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.