Create multiple indexes

Today I have multiple views in order to use they ability to filter and sort, for example if I have employee object the I have several views for it:

  • emit(employeeId);
  • emit(employeeAddress)
  • emit(employeeName)
  • This view are used mainly for filtering and sorting. Now that I can do that in n1ql pretty easy by select queries, should I create multiple indexes like the views:

    • create index on employee(id)
    • create index on employee(address)
    • create index on employee(name)

    for better performance or one index on employee would be enough?



    In general, your index definitions should match your WHERE clauses. So if you have multiple queries, and each one has a different filter condition in the WHERE clause, then you should have multiple indexes.

    Thanks, shouldn’t it be also match with the sort?

    I meant with also sort and not just the where :slight_smile:
    Another one: can I create index with more than field like create index x on y(id, name, address)??
    And do a select like select * from y where id=“some value” ?

    If yes is there any best practice for that?

    No, the sort is independent. We generally do not use indexes for sorting, because our indexes are distributed and can perform distributed scans out of order (to increase scan throughput).