Hello. I'm developing an ecommerce site and real estate both of these I have to query a string using query.equal() and order documents by int that can be price or something else. I'm constantly getting an index error. Only ordering by $createdAt works. This is crucial to my sites. Any help.??
Hey there 👋
Indexes makes write operations tiny-bit slower, and read operations MUCH faster.
In Appwrite 1.2, you are required to setup index for each query that you make. Appwrite does it to keep your app safe by default. Complex query without index could make your application really slow.
With that said, solution is really simple. Let's say you run listDoucuments and get error like Index not found: category, price.
What you need to do is go to Appwrite Console (web console), enter your collection, and go into indexes tab. There, add a new index:
- Index key is just a name for you. Can be whatever
- Set type to
key. Thats basic index key with no special functionality - Add all attributes mentioned in the exception that you got (category, index)
- Set order to ASC. Direction doesn' make too much difference, so feel free to use ASC always if you don't want to dig deeper into theory about indexing
Aaand that's it 🎉 Your listDocuments should now run properly. I am attaching screenshot of the above example:
Oh, and this might get simpler in future. I believe we are researching option of making indexes optional. No promises yet.
Okay I got you
I hae done that, but the issue comes to last attribute for ordering documents
I have 6 string attributes that are on query.equal() the last one is price (int) which is desc
Hmm. Soo the problem is that index creation fails? because of the integer attribute?
Index creation succeeds but when I query I get that index not found indicating that last attributes with error code 400
Could you please share the error message with me?
Okay
i have found a solution: the ordering index shoud be a separate index from the rest queries
so i have created a query index of strings then a seaparate query for ordering
then it has worked
[SOLVED] string & int indexing error
Recommended threads
- Appwrite console is too heavy
The Appwrite console is too heavy And all of my services broken Any support , please
- Usage of the new Client() and dealing wi...
Hey guys, just a quick one - we had some web traffic the other day and it ended up bombing out - To put in perspective of how the app works, we have a Nuxt Ap...
- Increase by operators
I see appwrite have bunch of useful operators for querieng db. One more I would like to suggest is operators like increase the count of a int columns by 1,2.. ...