# Case insensitive search by using query in java API

**URL:** https://discuss.elastic.co/t/case-insensitive-search-by-using-query-in-java-api/61515
**Category:** Elasticsearch
**Created:** [September 26, 2016, 2:10pm UTC](https://discuss.elastic.co/t/case-insensitive-search-by-using-query-in-java-api/61515 "2016-09-26T14:10:25Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![prasad\_kp](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@prasad\_kp](https://discuss.elastic.co/u/prasad_kp)
#### Post date: [September 26, 2016, 2:10pm UTC](https://discuss.elastic.co/t/case-insensitive-search-by-using-query-in-java-api/61515/1 "2016-09-26T14:10:25Z")

</div>

Hi Team,  
I have 10 indices and each index type contains on an average of 7 string fields,

Now i want to do case insensitive search on this fields of all index,i tried this setting & mapping

"analyzer": {  
"lower\_keyword": {  
"type": "custom",  
"filter": "lowercase",  
"tokenizer": "keyword"  
}

name": {  
"type": "string",  
"analyzer": "lower\_keyword"  
}

It's working fine ,

But instead of declaring analyzer in different index's and mapping at different field levels is there any way to handle or able to do case insensitive search by forming query in java API.

Thanks for the help in advance...

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [September 26, 2016, 2:45pm UTC](https://discuss.elastic.co/t/case-insensitive-search-by-using-query-in-java-api/61515/2 "2016-09-26T14:45:05Z")

</div>

I'd use a template mapping so it would be applied automatically on every new index

---

<div class="post-metadata">

### Author: ![prasad\_kp](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@prasad\_kp](https://discuss.elastic.co/u/prasad_kp)
#### Post date: [September 26, 2016, 3:27pm UTC](https://discuss.elastic.co/t/case-insensitive-search-by-using-query-in-java-api/61515/3 "2016-09-26T15:27:20Z")

</div>

> [@prasad\_kp](#):
>
> type

Thank you very much David ,but still if its adjustable from JAVA API Query will be very helpful for us as already we have it all in production. If somehow we can make independent from mapping

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [September 26, 2016, 3:58pm UTC](https://discuss.elastic.co/t/case-insensitive-search-by-using-query-in-java-api/61515/4 "2016-09-26T15:58:45Z")

</div>

Can you describe a bit more what you have at this moment as a simple example so it will be easier to help you?

See this as an example: [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21)

---

<div class="post-metadata">

### Author: ![prasad\_kp](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@prasad\_kp](https://discuss.elastic.co/u/prasad_kp)
#### Post date: [September 26, 2016, 6:03pm UTC](https://discuss.elastic.co/t/case-insensitive-search-by-using-query-in-java-api/61515/5 "2016-09-26T18:03:55Z")

</div>

we have a index which is already in production ,and we have string field ,for this we don't have any analyser to lower case

For this filed we have value as Brand New ,but user is typing as brand new ,when we make a query search from java api ( term & match ) none of this worked.

we are looking for replica of SQL Lower function in elastic search ,where we will check by lower casing the filed value to the given search term

for ex: if user types as brand new /Brand New we will lower case this term  
and also make the search on particular filed by lower casing that particular filed value to lower.

SELECT LOWER('MYSTRING');

SELECT LOWER ('Elastic Seacrh Filed values');

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [September 26, 2016, 10:50pm UTC](https://discuss.elastic.co/t/case-insensitive-search-by-using-query-in-java-api/61515/6 "2016-09-26T22:50:31Z")

</div>

Can you please create an elasticsearch script which reproduces what you have in production?

---

<div class="post-metadata">

### Author: ![prasad\_kp](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@prasad\_kp](https://discuss.elastic.co/u/prasad_kp)
#### Post date: [September 27, 2016, 6:54am UTC](https://discuss.elastic.co/t/case-insensitive-search-by-using-query-in-java-api/61515/7 "2016-09-27T06:54:04Z")

</div>

Mapping

"BrandName": {  
"type": "string",  
"index": "not\_analyzed",  
"fields": {  
"raw": {  
"type": "string"  
}  
},

In this filed Brand Name we have " **Brand New**"

Query serach build  
is

{  
"query" : {  
"match" : {  
"BrandName" : {  
"query" : "brand new",  
"type" : "boolean"  
}  
}  
}  
}

**No response we are getting with this query ,as the actual value in ES DB is Brand New**

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 5, 2017, 10:17pm UTC](https://discuss.elastic.co/t/case-insensitive-search-by-using-query-in-java-api/61515/9 "2017-07-05T22:17:02Z")

</div>


