This post will provide an in depth and clear comparison between the Cloudant design documents. Provides an easy way to finalize which design document is applicable in your use case.
Types of Design Documents
- Cloudant Query
- Query Index
- Views
- Search Index
Comparison of Design Documents
Pagination | Sort | Filter | ||||
Bookmark | Skip | Limit | Max Limit | |||
Cloudant Query | Yes | Yes | No limit | At least one of the sort fields should be included in the selector. An index should exist, with all the sort fields in the same order | Accepts any fields in the selector. Only sort fields have restriction | |
Query Index | Yes | Yes | json: No limit text: 200 | At least one of the sort fields should be included in the selector. An index should exist, with all the sort fields in the same order | Accepts any fields in the selector. Only sort fields have restriction | |
Views | No | Yes | Yes | No limit | Sort is applied only to the key defined in the view function. Sort is specified using ‘descending = true’ | Filters only on indexed fields |
Search Index | Yes | No | Yes | 200 | Sorts an array of indexed fields | Filters only on indexed fields |
Performance tests
Time | Taken | in | seconds | … | Average | |
Search Index | 0.0921 | 0.1737 | 0.0824 | 0.0863 | 0.0862 | 0.1041 |
View (single key) | 0.0245 | 0.0296 | 0.0232 | 0.0263 | 0.0229 | 0.0253 |
View (multiple key) | 0.0294 | 0.0248 | 0.0251 | 0.03 | 0.0337 | 0.0286 |
Cloudant Query | 0.1245 | 0.201 | 0.2025 | 0.1224 | 0.2362 | 0.1773 |
Query Index (json) | 0.06 | 0.0553 | 0.0572 | 0.0609 | 0.0552 | 0.0577 |
Query Index (text) | 0.0643 | 0.0677 | 0.0727 | 0.0695 | 0.0856 | 0.0719 |
Test setup
- Database contains 100k records
- Each query resulted in 100 records
- Search Index is queried using a set of 100 search strings each concatenated with an OR clause
- Views performance is better when queried through startkey and endkey instead of a set of keys. The below values are calculated using a start and end key for 100 values
- Cloudant Query is performed with an $and clause where <search-string> $gt 1 and <search-string> $lt 100
Take aways
- The Search Index yields better performance and also has more flexible querying options. Any indexed field can be searched by itself or in conjunction with other indexed fields and hence search indexes are more flexible with future requirements.
- Views consume very less time when compared to other indexes. But they do not provide much flexibility in querying and sorting when compared with the Search Index
- Cloudant Query is slower when used without a query index. Further in Query index, json type index restricts on some operators usage whereas text type index has flexibility in this regard.
- Also, when compared to Search Index, Query Index is taking more time while using regex match in the query
- Both Search Index and text type Query Index have maximum limit of 200 records. Behind the screen, text type index uses Lucene indexer similar to Search Index
Conclusion
Use Views or Search Indexes for your application use cases.