I have an index with many fields and I want to be able to search by some of them at the same time, and this search should support partial match (in any position), case insensitive, support some symbols.
Example of my index:
PUT my_index
{
settings: {
analysis: {
analyzer: {
analyzerCaseInsensitive: {
filter: ['lowercase'],
tokenizer: 'keyword',
},
default: {
type: 'keyword',
},
},
},
},
mappings: {
properties: {
id: {
type: 'text',
analyzer: 'analyzerCaseInsensitive'
},
email: {
type: 'text',
analyzer: 'analyzerCaseInsensitive'
},
fullName: {
type: 'text',
analyzer: 'analyzerCaseInsensitive'
}
}
}
}
And then to search I'm using this query:
GET my_index/_search
{
from: 0,
size: 10,
query: {
bool: {
must: [
{
{
query_string: {
query: `*{search}*`,
fields: ['id', 'email', 'fullName'],
}
}
}
]
}
}
}
With this query I'm able to search partial match, case insensitive, and some symbols, but I'm not able to search text with whitespace in the middle to get those that match only that literal text.
I will describe some examples of what I want to achieve.
--- FIELDS ---
Id field is an uuidv4, so the format is something like: "6e0baaae-ff10-4812-b27d-ca307560b9e3".
fullName field could include whitespace like, "Jhon Doe".
--- EXPECTED BEHAVIOR---
PUT my_index/_doc/1
{
"id": "6e0baaae-ff10-4812-b27d-ca307560b9e3",
"email": "jhon.doe@gmail.com",
"fullName": "Jhon Doe"
}
PUT my_index/_doc/2
{
"id": "3b8605f9-1fad-4b25-a061-ab0943f7d55e",
"email": "jhonny_saur@hotmail.com",
"fullName": "Scott Doe"
}
So if I search "jho", I expect both, because it's included in the fullName of 1 and in the email of 2.
Search "jhon Doe", I expect only the 1, because it's the only that match the whole text.
Search "nny", I expect the 2, because it's included in the email.
How can I improve my index or query to support this? Thanks