# How to search case sensitive in elasticsearch without mapping

**URL:** <https://discuss.elastic.co/t/how-to-search-case-sensitive-in-elasticsearch-without-mapping/139482>\
**Category:** Elasticsearch\
**Created:** [July 11, 2018, 6:46am UTC](https://discuss.elastic.co/t/how-to-search-case-sensitive-in-elasticsearch-without-mapping/139482 "2018-07-11T06:46:43Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![satyaveer1](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@satyaveer1](https://discuss.elastic.co/u/satyaveer1)\
**Post date:** [July 11, 2018, 6:46am UTC](https://discuss.elastic.co/t/how-to-search-case-sensitive-in-elasticsearch-without-mapping/139482/1 "2018-07-11T06:46:43Z")

</div>

I am creating an elasticsearch app where i need to case sensitive search without use of mapping. So please suggest me how to do this.

---

<div class="post-metadata">

**Author:** ![klof](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/klof/32/31590_2.png) [@klof](https://discuss.elastic.co/u/klof)\
**Post date:** [July 11, 2018, 7:14am UTC](https://discuss.elastic.co/t/how-to-search-case-sensitive-in-elasticsearch-without-mapping/139482/2 "2018-07-11T07:14:42Z")

</div>

Without mapping, by default your fields will be a `keyword` type, meaning not analyzed by Elasticsearch.  
In that case you will make a term search, on the exact match.

[https://www.elastic.co/guide/en/elasticsearch/reference/master/keyword.html](https://www.elastic.co/guide/en/elasticsearch/reference/master/keyword.html)

---

<div class="post-metadata">

**Author:** ![satyaveer1](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@satyaveer1](https://discuss.elastic.co/u/satyaveer1)\
**Post date:** [July 12, 2018, 7:38am UTC](https://discuss.elastic.co/t/how-to-search-case-sensitive-in-elasticsearch-without-mapping/139482/3 "2018-07-12T07:38:04Z")

</div>

Is term query case sensitive? Actually when i search word "Dog" with term query it shows the result for dog and Dog both where i want result only for Dog(exact match) without mapping.How can i solve this problem please suggest me.

---

<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:** [July 12, 2018, 8:01am UTC](https://discuss.elastic.co/t/how-to-search-case-sensitive-in-elasticsearch-without-mapping/139482/4 "2018-07-12T08:01:10Z")

</div>

But you did not change the mapping, did you?

If you can't make it work, provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![klof](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/klof/32/31590_2.png) [@klof](https://discuss.elastic.co/u/klof)\
**Post date:** [July 12, 2018, 8:13am UTC](https://discuss.elastic.co/t/how-to-search-case-sensitive-in-elasticsearch-without-mapping/139482/5 "2018-07-12T08:13:20Z")

</div>

Without mapping, you should use :

```
{
  "query": {
    "term": {
      "your_field.keyword": {
        "value": "Dog"
      }
    }
  }
}

```

If this doesn't work,  
Indeed could you provide us, more details : mapping + query?

---

<div class="post-metadata">

**Author:** ![satyaveer1](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@satyaveer1](https://discuss.elastic.co/u/satyaveer1)\
**Post date:** [July 12, 2018, 9:08am UTC](https://discuss.elastic.co/t/how-to-search-case-sensitive-in-elasticsearch-without-mapping/139482/6 "2018-07-12T09:08:51Z")

</div>

`I am working on an elasticsearch app i want the case sensitive search but i am facing the problem.  
I am using the process just given below -

Step -1 index creating and insert records in to it.

PUT index

PUT index/doc/1  
{  
"animal": "Quick fox or dog "  
}  
PUT index/doc/2  
{  
"animal": "quick fox or dog "  
}

Step 2- Now searching

GET index/\_search  
{  
"query": {  
"term": {  
"animal": "Quick"  
}  
}  
}

Then result show none  
{  
"took": 0,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"skipped": 0,  
"failed": 0  
},  
"hits": {  
"total": 0,  
"max\_score": null,  
"hits": []  
}  
}

But when i use the query with word "quick" given below -  
GET index/\_search  
{  
"query": {  
"term": {  
"animal": "quick"  
}  
}  
}  
it shows the result like -  
{  
"took": 1,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"skipped": 0,  
"failed": 0  
},  
"hits": {  
"total": 2,  
"max\_score": 0.2876821,  
"hits": [  
{  
"\_index": "index",  
"\_type": "doc",  
"\_id": "2",  
"\_score": 0.2876821,  
"\_source": {  
"animal": "quick fox or dog "  
}  
},  
{  
"\_index": "index",  
"\_type": "doc",  
"\_id": "1",  
"\_score": 0.2876821,  
"\_source": {  
"animal": "Quick fox or dog "  
}  
}  
]  
}  
}

so i am unable to find exact mach of searched word "Quick".

Please suggest me so that i can solve this problem.

---

<div class="post-metadata">

**Author:** ![satyaveer1](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@satyaveer1](https://discuss.elastic.co/u/satyaveer1)\
**Post date:** [July 12, 2018, 9:28am UTC](https://discuss.elastic.co/t/how-to-search-case-sensitive-in-elasticsearch-without-mapping/139482/8 "2018-07-12T09:28:45Z")

</div>

i am using the query -

GET index/\_search  
{  
"query": {  
"term": {  
"animal.keyword":{"value":"Quick"}  
}  
}  
}

even then no result found.

---

<div class="post-metadata">

**Author:** ![tdasch](https://avatars.discourse-cdn.com/v4/letter/t/58f4c7/32.png) [@tdasch](https://discuss.elastic.co/u/tdasch)\
**Post date:** [July 12, 2018, 9:52am UTC](https://discuss.elastic.co/t/how-to-search-case-sensitive-in-elasticsearch-without-mapping/139482/9 "2018-07-12T09:52:44Z")

</div>

Can you provide your mapping for the index please?

---

<div class="post-metadata">

**Author:** ![satyaveer1](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@satyaveer1](https://discuss.elastic.co/u/satyaveer1)\
**Post date:** [July 12, 2018, 9:55am UTC](https://discuss.elastic.co/t/how-to-search-case-sensitive-in-elasticsearch-without-mapping/139482/10 "2018-07-12T09:55:54Z")

</div>

I am not using mapping as i discussed above. I want exact search without use of mapping if i use mapping its create a problem of re-indexing to remove or change mapping .

---

<div class="post-metadata">

**Author:** ![tdasch](https://avatars.discourse-cdn.com/v4/letter/t/58f4c7/32.png) [@tdasch](https://discuss.elastic.co/u/tdasch)\
**Post date:** [July 12, 2018, 9:57am UTC](https://discuss.elastic.co/t/how-to-search-case-sensitive-in-elasticsearch-without-mapping/139482/11 "2018-07-12T09:57:38Z")

</div>

If mapping changes need to be made on your current data then yes, a re-index would be needed. Would it be possible to show your mapping to help troubleshoot? Thanks!

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 12, 2018, 10:00am UTC](https://discuss.elastic.co/t/how-to-search-case-sensitive-in-elasticsearch-without-mapping/139482/12 "2018-07-12T10:00:33Z")

</div>

All fields are mapped in Elasticsearch, so you can not run without mappings. What happens when you do not explicitly specify mappings is that Elasticsearch applies default mappings dynamically, which may or may not suit your needs.

---

<div class="post-metadata">

**Author:** ![satyaveer1](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@satyaveer1](https://discuss.elastic.co/u/satyaveer1)\
**Post date:** [July 12, 2018, 10:04am UTC](https://discuss.elastic.co/t/how-to-search-case-sensitive-in-elasticsearch-without-mapping/139482/13 "2018-07-12T10:04:04Z")

</div>

When i use the below given mapping then result found

PUT /index  
{  
"settings": {  
"analysis": {  
"analyzer": {  
"mymapping": {  
"type": "custom",  
"tokenizer": "standard"  
}  
}  
}  
},  
"mappings": {  
"type": {  
"properties": {  
"animal": {  
"type": "string",  
"analyzer": "mymapping"  
}  
}  
}  
}  
}

But i don't want to use of this mapping to avoid the re-indexing problem.

---

<div class="post-metadata">

**Author:** ![satyaveer1](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@satyaveer1](https://discuss.elastic.co/u/satyaveer1)\
**Post date:** [July 12, 2018, 10:06am UTC](https://discuss.elastic.co/t/how-to-search-case-sensitive-in-elasticsearch-without-mapping/139482/14 "2018-07-12T10:06:47Z")

</div>

thanks for this

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 12, 2018, 10:09am UTC](https://discuss.elastic.co/t/how-to-search-case-sensitive-in-elasticsearch-without-mapping/139482/15 "2018-07-12T10:09:50Z")

</div>

You have to use some mapping, and if you want to change it you will need to reindex.

---

<div class="post-metadata">

**Author:** ![satyaveer1](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@satyaveer1](https://discuss.elastic.co/u/satyaveer1)\
**Post date:** [July 12, 2018, 10:13am UTC](https://discuss.elastic.co/t/how-to-search-case-sensitive-in-elasticsearch-without-mapping/139482/16 "2018-07-12T10:13:19Z")

</div>

Thanks for your suggestion.

---

<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:** [August 9, 2018, 10:13am UTC](https://discuss.elastic.co/t/how-to-search-case-sensitive-in-elasticsearch-without-mapping/139482/17 "2018-08-09T10:13:19Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
