Search case insensitive

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.

Change the mapping and don't analyze the text field

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

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

Here is a way to do it:

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"
    }
  }
}
1 Like

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"}}}}}}}

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