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
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...
- Edit ID of an existing collection
Hi there. Is it possible to edit an ID of an existing collection? Right now it looks impossible from AppWrite cloud at least.
- Current User is Not authorized
recreating same Thread