Goal
I want to execute an elasticsearch query that searches an index by preferred (first) name and last name.
The results I am looking for are as follows:
Name1: Josh Allen Name2: Joseph Albright Name3: Jose Abreu Name4: Allen Iverson
A query "Jos*" should return Name1, Name2, and Name3.
A query "Josh*" should only return Name1.
A query "Josh Al*" should also only return Name1. This should not return Name4.
Problem
prefName and lastName are two separate fields in the index. This seems to make things a little more tricky.
Index Definition
{
"employee-profile2020.11.16": {
"aliases": {
"employeeprofile": {}
},
"mappings": {
"dynamic": "false",
"properties": {
"jobFamilyGroup": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"personDTO": {
"properties": {
"lastName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"prefName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"status": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
}
}
}
}
Attempt
I think I am close to a solution using query_string. Here is the query I am executing to find an active user, with a particular jobFamilyGroup, by prefName and lastName:
{
"query": {
"bool": {
"must": [
{
"match": {
"personDTO.status": "A"
}
},
{
"wildcard": {
"jobFamilyGroup": {
"value": "athlete"
}
}
},
{
"query_string": {
"query": "Allen Ive*",
"fields": [
"personDTO.prefName^3",
"personDTO.lastName"
]
}
}
]
}
}
}
The results return both "Allen Iverson" and "Josh Allen". Boosting the score on personDTO.prefName seems to help a bit, but I am only wanting Allen Iverson to return here since prefName is established before the space.
Is there a way that I can further filter these results to only give me prefName with "Allen" instead of looking at both prefName and lastName? Please let me know if more information is needed. Thank you.