No proper explanation/examples for Indexing couchbaselite

I’m unable to find any good example showing indexing properly using Swift. I found one example of github of Travel-sample. My confusions are:

  1. Can we do indexing on particlular type of document instead of the entire database?
  2. lets suppose, two document types having same property such as “city”. So, Will it take an indexing for both or single? If it takes for both of them then, How to restrict indexing for only one document type?

As joins are taking much more time for execution of the query, I want to apply indexing to it. Can you please solve this confusions & provide me better demos for it?

We don’t support partial indexes yet, so indexes always cover the entire database.

  1. lets suppose, two document types having same property such as “city”. So, Will it take an indexing for both or single? If it takes for both of them then, How to restrict indexing for only one document type?

Both types will be indexed. This won’t produce incorrect results, since your query should already be testing ...AND type='type1', but it won’t be optimally fast.

You can speed this up by creating an index on type and city, with type coming first (primary key). That way the query optimizer will scan only the range of the index corresponding to the doc type you specify in the query.

1 Like