
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
- I am facing this error: type 'Null' is ...
When attempting to fetch areas from the area collection, the application throws an error: "type 'Null' is not a subtype of type 'int.'" This issue originates in...
- Adding Domain to Sites [Self Hosted]
I am struggling to get this working. I stood-up a new server and deployed appwrite 1.7.4. I added update .env file _APP_DOMAIN=appwrite.mydomain.com _APP_DOMAI...
- #support
<#1072905050399191082> any help on that?
