# Case-sensitive search

**URL:** <https://discuss.elastic.co/t/case-sensitive-search/53355>\
**Category:** Elasticsearch\
**Created:** [June 20, 2016, 6:23pm UTC](https://discuss.elastic.co/t/case-sensitive-search/53355 "2016-06-20T18:23:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![currymj](https://avatars.discourse-cdn.com/v4/letter/c/c68b51/32.png) [@currymj](https://discuss.elastic.co/u/currymj)\
**Post date:** [June 20, 2016, 6:23pm UTC](https://discuss.elastic.co/t/case-sensitive-search/53355/1 "2016-06-20T18:23:52Z")

</div>

I'm trying to build an index for case-sensitive search. The index settings I'm using are at the bottom (including defining a custom "caseSensitive" analyzer).

If I perform a query like

```auto
GET /emails_text/_search
{
  "fields": [
    "text"
  ],
  "query": {
    "match": {
      "text": {
        "query": "begin",
        "analyzer": "caseSensitive"
      }
    }
  }
}

```

then it seems that the query itself is case sensitive (searching for capitalized terms gives no results), but the actual index seems to be all lowercased -- a lowercase query gives results for both lower and uppercase terms.

What am I doing wrong here? Am I querying wrong or should I be taking a different approach?

My index settings at creation time (ignore the stuff about shingles):

```auto
{
  "settings": {
    "analysis": {
      "filter": {
        "shingle_filter": {
          "type": "shingle",
          "max_shingle_size": 5
        }
      },
      "analyzer": {
        "shingles": {
          "tokenizer": "standard",
          "filter": [
            "shingle_filter"
          ]
        },
        "caseSensitive": {
          "tokenizer": "standard",
          "filter": [
            "standard",
            "stop"
          ]
        }
      }
    },
    "mappings": {
      "email": {
        "properties": {
          "sent": {
            "type": "date",
            "format": "epoch_millis"
          },
          "text": {
            "type": "string",
            "index_analyzer": "caseSensitive",
            "search_analyzer": "caseSensitive",
            "term_vector": "with_positions_offsets_payloads",
            "store": true,
            "fields": {
              "shingle": {
                "type": "string",
                "index_analyzer": "shingles",
                "search_analyzer": "caseSensitive"
              }
            }
          }
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![softwaredoug](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/softwaredoug/32/22681_2.png) [@softwaredoug](https://discuss.elastic.co/u/softwaredoug)\
**Post date:** [June 20, 2016, 8:02pm UTC](https://discuss.elastic.co/t/case-sensitive-search/53355/2 "2016-06-20T20:02:19Z")

</div>

I pasted your settings to Sense and I was flabergasted for a while. Until I tried this

```auto
GET /test/_mapping

```

And the response was simply `{}`.

well... anyway it turns out that your "mappings" was nested under "settings". It needs to be a _sibiling_ of settings, as in:

```auto
PUT /test
{
  "settings": {
    "analysis": {
      "analyzer": {
        "caseSensitive": {
          "type": "custom",
          "tokenizer": "whitespace"      
        }
      }
    }
  },
  "mappings": {
      "email": {
        "properties": {        
          "text": {
            "type": "string",
            "analyzer": "caseSensitive",
            "search_analyzer": "caseSensitive"          
          }
        }
      }
    }
}

```

---

<div class="post-metadata">

**Author:** ![currymj](https://avatars.discourse-cdn.com/v4/letter/c/c68b51/32.png) [@currymj](https://discuss.elastic.co/u/currymj)\
**Post date:** [June 20, 2016, 8:38pm UTC](https://discuss.elastic.co/t/case-sensitive-search/53355/3 "2016-06-20T20:38:10Z")

</div>

Well, problem solved.

Definitely one of my dumber mistakes, although I wonder why elastic just accepts an error like that silently? Was I changing some other setting that didn't matter to this issue?

---

<div class="post-metadata">

**Author:** ![softwaredoug](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/softwaredoug/32/22681_2.png) [@softwaredoug](https://discuss.elastic.co/u/softwaredoug)\
**Post date:** [June 21, 2016, 12:30pm UTC](https://discuss.elastic.co/t/case-sensitive-search/53355/4 "2016-06-21T12:30:29Z")

</div>

I've done this before. I agree it should be treated as an error. At least catch this specific common mistake.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [June 22, 2016, 2:33am UTC](https://discuss.elastic.co/t/case-sensitive-search/53355/5 "2016-06-22T02:33:11Z")

</div>

Please feel free to raise an issue on github for this, then we can fix it! 🙂

---

<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:41pm UTC](https://discuss.elastic.co/t/case-sensitive-search/53355/6 "2017-07-05T22:41:35Z")

</div>


