Cloudant Fundamentals: Indexing

Primary or secondary? Type json or text? Understanding your options (part 9 of 10)

Glynn Bird
Jul 12, 2018 · 3 min read
Photo by NeONBRAND on Unsplash

What is an index?

A database index is just like an index in a book or a biblical concordance. It is a sorted data structure that allows quick access to a portion of the data.

Index types — json & text

Cloudant Query has two types of index — json and text.

Indexing strategies

The job of an index is to help the database to reduce the volume of data it’s working with to a manageable size. Imagine you have a query like this for a database of movies:

  • the number of movies that star an actor

Other tips:

  • Use the POST /db/_explain to see how Cloudant picks an index for a specified query.
  • Cloudant allows you to specify the index you want the database to use at query time. This is good practice as you remove any ambiguity in index selection.
  • Consider creating partial Cloudant indicies if you are only ever interested in querying a subset of your database (i.e., you could eliminate preliminary blog posts from your index and only include published posts in a partial index).
  • There’s always Cloudant’s MapReduce, Search and Geospatial indexes for a lower-level querying experience.
  • Not all queries are “Cloudant-shaped”. If you are building leader boards or counting distinct values, you might want to consider rolling your own custom index outside of Cloudant.

Next time

In the final part of this series, we’ll look at performing aggregations using Cloudant.

IBM CODAIT

Things we made with data at IBM’s Center for Open Source Data and AI Technologies.

Glynn Bird

Written by

Developer @ IBM. https://glynnbird.com

IBM CODAIT

Things we made with data at IBM’s Center for Open Source Data and AI Technologies.