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
- Weird permission failure
when creating an account I use following methods: ``` Future<void> register(String email, String password, String username) async { final user = await accoun...
- Flutter Android oAuth is no more working
I currently don't get the oAuth login to work in flutter android. it works on ios and on web. but when try to use it on Android, i get to the point where the ca...
- Relation Question
How do I create a relation from table y to an others x.$id. in my example I have a users table where I use Appwrites unique User IDs and I want other tables fo...