Rahul
Rahul

Reputation: 2617

Creating index in couchbase

System

enter image description here

I have not created any bucket so started creating bucket.

enter image description here

Bucket configuration is listed below.

enter image description here

I added a document enter image description here

Now i tried to run n1ql command and it give me following error.

[
  {
    "code": 4000,
    "msg": "No index available on keyspace `default`:`test` that matches your query. Use CREATE PRIMARY INDEX ON `default`:`test` to create a primary index, or check that your expected index is online.",
    "query": "select * from test;"
  }
]

Upvotes: 1

Views: 2974

Answers (1)

Matthew Groves
Matthew Groves

Reputation: 26169

This is expected behavior. No indexes are created automatically in Couchbase, not even a primary index.

You can create a primary index with:

CREATE PRIMARY INDEX ON `test`

That's enough to make your query work. With a single document, it won't be too slow. But in production, you'll need to create indexes that are better tailored to your queries (just like in a relational database).

I recommend checking out the documentation to learn more about indexes.

Another tool that can be helpful is the Index Advisor. It can recommend better indexes, based on your query. Click the "Advice" button in Query Workbench to try it out.

Upvotes: 2

Related Questions