# Search case insensitive

**URL:** <https://discuss.elastic.co/t/search-case-insensitive/82648>\
**Category:** Elasticsearch\
**Created:** [April 18, 2017, 2:37am UTC](https://discuss.elastic.co/t/search-case-insensitive/82648 "2017-04-18T02:37:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ToujouAya](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@ToujouAya](https://discuss.elastic.co/u/ToujouAya)\
**Post date:** [April 18, 2017, 2:37am UTC](https://discuss.elastic.co/t/search-case-insensitive/82648/1 "2017-04-18T02:37:18Z")

</div>

Hi guys.  
I want to search string contain string in field. Like search **like** in SQL  
I tried to use the regex to search.  
`$params["query"]["bool"]["filter"][]["regexp"][$item_key] = '.*'.$search_pattern.'.*'`

I can only search for lower word. For upper word , it is not working.

Does anyone have any idea for search in case insensitive?  
Thank you very much.

---

<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:** [April 18, 2017, 3:02am UTC](https://discuss.elastic.co/t/search-case-insensitive/82648/2 "2017-04-18T03:02:01Z")

</div>

Change the mapping and don't analyze the text field

---

<div class="post-metadata">

**Author:** ![ToujouAya](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@ToujouAya](https://discuss.elastic.co/u/ToujouAya)\
**Post date:** [April 18, 2017, 4:38am UTC](https://discuss.elastic.co/t/search-case-insensitive/82648/6 "2017-04-18T04:38:48Z")

</div>

I tried your suggestion but it is not work

my new mapping is like this

```
`'mappings' => [
            'items' => [
                "title" => [
                    "type" => "text",
                    "fields" => [
                        "keyword" => [
                            "type" => "keyword",
                        ]
                    ],
                    "fielddata" => true,
                    "index" => "not_analyzed",
                ]
            ]
        ]`

```

But it doesn't work

Example:  
my title is : ABC  
if search text is : abc -\> has result  
if search text is : ABC -\> no result

---

<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:** [April 19, 2017, 5:42pm UTC](https://discuss.elastic.co/t/search-case-insensitive/82648/7 "2017-04-19T17:42:29Z")

</div>

`index: not_analyzed` is ignored. It should be only true or false.

Here is a way to do it:

```auto
DELETE test
PUT test
{
  "mappings": {
    "type": {
      "properties": {
        "foo": {
          "type": "text",
          "analyzer": "keyword"
        }
      }
    }
  }
}
PUT test/type/1
{
  "foo": "ABC"
}
# Match
GET test/_search
{
  "query": {
    "match": {
      "foo": "ABC"
    }
  }
}
# Does not Match
GET test/_search
{
  "query": {
    "match": {
      "foo": "abc"
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![ToujouAya](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@ToujouAya](https://discuss.elastic.co/u/ToujouAya)\
**Post date:** [April 20, 2017, 1:27am UTC](https://discuss.elastic.co/t/search-case-insensitive/82648/8 "2017-04-20T01:27:01Z")

</div>

Thank you. I have changed a little and it's work now

```
{ "mappings": { "type": { "properties": {"foo": { "type": "text", "analyzer": "standard", "fielddata" : true, "fields" : { "keyword" => {"type" : "keyword"}}}}}}}
```

---

<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:** [May 18, 2017, 1:38am UTC](https://discuss.elastic.co/t/search-case-insensitive/82648/9 "2017-05-18T01:38:28Z")

</div>

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