question

GuilhermeMolin-8917 avatar image
0 Votes"
GuilhermeMolin-8917 asked AnuragSharma-MSFT commented

CosmosDB accent (diacritics) insensitive query

Hello, I've searched everywhere but did not found the anwser I was looking for.
How do I query CosmosDB ignoring accents?
Example:
{"id": "1", "name": "Émpresa 1" }
{"id": "2", "name": "empresa 2" }

SELECT * FROM container_name WHERE name LIKE 'empresa%'

I want to retrieve both records from this query, how can I do that?
If it's not possible "out of the box" then is there any workaround?

azure-cosmos-db
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @GuilhermeMolin-8917, welcome to Microsoft Q&A forum.

I think its not possible for Cosmos DB to treat both of them as same and retrieve by using the query you mentioned as both the strings represent different values. We might need to used like operator excluding the diacritics characters. However I am reaching out to product team as well to see if this is any way possible.

0 Votes 0 ·

1 Answer

AnuragSharma-MSFT avatar image
0 Votes"
AnuragSharma-MSFT answered AnuragSharma-MSFT commented

Hi @GuilhermeMolin-8917,

One way to do it is through the like operator by removing the diacritics character as mentioned in the below thread on Stack:

 SELECT * FROM c WHERE c.name LIKE "%mpresa%"

CosmosDB accent (diacritics) insensitive query

Same article talks about using Azure Cognitive Search which can also be used.

Please let us know if this helps.


Please don't forgot to click on accept it as answer button 132284-image.png wherever the information provided helps you. This can be beneficial to other community members as well.



image.png (8.9 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for the answer @AnuragSharma-MSFT unfortunally this only works for this specific case, also if I have "Ampresa", "Impresa", etc. It would select too, which is not what I want...
I want to know if "É" and "E" can be treated equally.

0 Votes 0 ·

Hi @GuilhermeMolin-8917, thanks for your reply. You are right that like query could select more items if they match the search string, which is kind of limitation that we have currently. You can please check if Azure Search can help you there:

Index data from Azure Cosmos DB using SQL or MongoDB APIs


0 Votes 0 ·