From 4717bdaecf13d82d94fa0dfdd0ef2d15112f01ed Mon Sep 17 00:00:00 2001 From: Voroshilov Maksim Date: Thu, 30 Nov 2023 15:14:22 +0200 Subject: [PATCH] Added description for indexing CouchDB. Signed-off-by: Voroshilov Maksim --- docs/source/couchdb_tutorial.rst | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/docs/source/couchdb_tutorial.rst b/docs/source/couchdb_tutorial.rst index e2e62a217e0..d48ddff0f93 100644 --- a/docs/source/couchdb_tutorial.rst +++ b/docs/source/couchdb_tutorial.rst @@ -220,6 +220,34 @@ the CouchDB recommended practice. } +If you want to add sorting to your indexing, add a sort type. Then you can query result at needed sort. Example below. + +.. code:: json + + { + "index":{ + "fields":[ + { + "owner":"desc" + }, + { + "color":"desc" + }, + { + "size":"desc" + } + ] // Names of the fields to be queried and sorted for descending. + }, + "ddoc":"index3Doc", + "name":"index3", + "type":"json" + } + +.. tip:: Be aware if you want to have good performance in your query, put the most + restrictive field in the first place to limit the results the most. + In our case ``owner`` should be the first value in index ``fields``. + Because the ``owner`` carries a unique user identifier. + In general, you should model index fields to match the fields that will be used in query filters and sorts. For more details on building an index in JSON format refer to the `CouchDB documentation `__.