Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do a Case Insensitive search on Azure DocumentDb?

Tags:

is it possible to perform a case insensitive search on DocumnetDb?

Let's say I have a record with 'name' key and value as "Timbaktu"

This will work:

select * from json j where j.name  = "Timbaktu" 

This wont:

select * from json j where j.name  = "timbaktu" 

So how do yo do a case insensitive search?

Thanks in advance.

Regards.

like image 434
Codehelp Avatar asked May 28 '15 17:05

Codehelp


People also ask

How do you make a case insensitive search?

Case insensitive SQL SELECT: Use upper or lower functions or this: select * from users where lower(first_name) = 'fred'; As you can see, the pattern is to make the field you're searching into uppercase or lowercase, and then make your search string also be uppercase or lowercase to match the SQL function you've used.

Is cosmos case-sensitive?

When the JSON event does not contain an id field, a unique ID (for example, 5abcD-56efgh0-ijkl43 ) is generated for each document. Since Cosmos DB is case-sensitive, when the JSON event includes a field named Id , iD , or ID , it is imported as a separate field.

What is case insensitive search?

By default, searches are case-insensitive. You can make your search case-sensitive by using the case filter. For example, the following search returns only results that match the term HelloWorld . It excludes results where the case doesn't match, such as helloWorld or helloworld . case:yes HelloWorld.

Which are common use cases for document DB Cosmosdb?

A common use case for Azure Cosmos DB is to store and query user generated content (UGC) for web, mobile, and social media applications. Some examples of UGC are chat sessions, tweets, blog posts, ratings, and comments.


1 Answers

There are two ways to do this. 1. use the built-in LOWER/UPPER function, for example,

select * from json j where LOWER(j.name) = 'timbaktu' 

This will require a scan though. Another more efficient way is to store a "canonicalized" form e.g. lowercase and use that for querying. For example, the JSON would be

{ name: "Timbaktu", nameLowerCase: "timbaktu" } 

Then use it for querying like:

select * from json j WHERE j.nameLowerCase = "timbaktu" 

Hope this helps.

like image 80
Aravind Krishna R. Avatar answered Sep 29 '22 15:09

Aravind Krishna R.