Sub string search along with case Insensitive and special characters

Hi There,

Is it possible to query(wildcard search) on index with case insensitive as well as special characters without lower casing the input data .

My requirements are below:
a). Data contains small case, upper case and special characters.
b). Query string(which may contain capital or small case), it should return the result irrespective of case. i.e input string "a" can match with both "a" and "A" .

Example:
Data:
1. Sampl,e
2. samp-le
3. SAmp&le
4. sAmp%le

when the query with *sa* in elastic. It should be able to return: all the four Sampl,e, samp-le, SAmp&le, sAmp%le (irrespective of case).

when the query with *-* in elastic. It should be able to return: samp-le

when the query with *&* in elastic. It should be able to return: SAamp&le.

It should also work for remaining special characters too like(, %).

In-order to solve above problem. I created Index like below.

PUT my_index
{
"index" : {
"analysis" : {
"analyzer" : {
"default" : {
"type" : "whitespace",
"tokenizer" : "whitespace"
}
}
}
}
}

I created one type called mytype with not analyzed fields.

PUT my_index/_mapping/mytype
{
"properties": {
"data": {
"type":"keyword",
"index":"not_analyzed"

    }
}

}

I loaded data like below into elastic server.

POST my_index/mytype/1
{
"data":"Sampl,e"
}

POST my_index/mytype/2
{
"data":"samp-le"
}

POST my_index/mytype/3
{
"data":"SAmp&le"
}

POST my_index/mytype/4
{
"data":"sAmp%le"
}

**my query is below for above data to search sa:
GET my_index/_search
{
"query": {
"query_string": {
"query": "*sa*"
}
}
}

RESULT:
It's only able to search: samp-le (String 2).

Expected:
It should be return all the String from index which contains sa.

It's should be able to search all special characters.

What should I modify in schema or query, to get desired results(It should work for case insensitive as well as special characters)

NOTE : Converting input data to lower case it's not solution to my case( I have to pass exact data to another component)

Thanks in advance
Suresh Y

1 Like

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