I just duplicated mu customer database into Elasticsearch for faster result.
On my listing page I have a search field to search any string into my customer db. the search should be able to match a result on email, first name, last name, id and phone.
I created an nGram
filter to be able to match only parts of query
ES.client.indices.putSettings({
index: `customer`,
body: {
analysis : {
index_analyzer: {
my_index_analyzer: {
type: "custom",
tokenizer: "standard",
filter: ["lowercase", "mynGram"]
}
},
search_analyzer: {
my_search_analyzer: {
type: "custom",
tokenizer: "standard",
filter: [ "standard", "lowercase", "mynGram"]
}
},
filter: {
mynGram: {
type: "nGram",
min_gram: 2,
max_gram: 30
}
}
},
max_ngram_diff: 30
}
})
and my query is
{
"index":"customer",
"pageNum":1,
"perPage":20,
"query":{
"bool":{
"must":[
{
"bool":{
"should":[
{
"match":{
"organizationId":"org_1"
}
},
{
"match":{
"organizationId":"org_2"
}
}
]
}
},
{
"multi_match":{
"fields":[
"id",
"email",
"firstName",
"lastName",
"phone"
],
"query":"loc"
}
}
]
}
},
"sort":{
"createdAt":{
"order":"desc"
}
}
}
But this is not working as I want.
For example one of my emails is test@geo.loc
and if I search for loc
I have no result.
I made another test with 4 emails test@geo.loc
test1@test.com
test2@test.com
test@test.com
. Looking for test
it only returns test@geo.loc
and test@test.com
should return all the results
Other test one of the phones number is 2211111111
if I am looking for 1111
I have no result but 2211111111
works