How to make search using keyword field with ignorecase


(kanchan) #1

Hi,
I am using keyword field for exact match.but it is case sensetive.how could i make it case insensetive.
code which I use for searching is:

GET /ciq/_search
{

"query": {
"bool": {
"must": [
{
"match": {
"companyname.keyword": {
"query": "SHELL PRIVATE LTD",
"analyzer": "coal_asset_text_general_likely"
}
}
}
]
}
}
}

it is not giving records where company name in lowercase.how could i make it possible.


(Tyler Smalley) #2

You will need to use a custom normalizer, for example:

PUT ciq
{
  "settings": {
    "analysis": {
      "normalizer": {
        "lowercase_normalizer": {
          "type": "custom",
          "char_filter": [],
          "filter": ["lowercase"]
        }
      }
    }
  },
  "mappings": {
    "doc": {
      "properties": {
        "companyname.keyword": {
          "type": "keyword",
          "normalizer": "lowercase_normalizer"
        }
      }
    }
  }
}


POST ciq/doc
{
  "companyname.keyword": "foo"
}

POST ciq/doc
{
  "companyname.keyword": "Foo"
}

GET /ciq/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "companyname.keyword": {
              "query": "foo"
            }
          }
        }
      ]
    }
  }
}

(kanchan) #3

ok. but if I will search for exact match for lowercase foo, it will only show ''foo'' as doc but my requirement is It should match only letter not case.
suppose if I query for foo or Foo, it should show both docs.

How can I achieve it using keyword field.


(system) #4

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