I have an index in OpenSearch which contains documents like this:
{
"employee": {
"id": "4",
"fullName": "Ivanov Ivan Ivanovich"
}
}
I want to create a query which can search me documents by fullName field in way like this: “Ivanov Ivan” or “Ivanov I I”.
Let’s assume that index contains this documents:
{
"employee": {
"id": "4",
"fullName": "Ivanov Ivan Ivanovich"
}
},
{
"employee": {
"id": "5",
"fullName": "Ivanov Gleb Glebovich"
}
}
I wrote this query:
GET /contact/_search
{
"query": {
"bool": {
"must": [
{
"match_phrase_prefix": {
"employee.fullName": "Ivanov"
}
},
{
"match_phrase_prefix": {
"employee.fullName": "Ivan"
}
}
]
}
}
}
I expect to get a single result of "fullName": "Ivanov Ivan Ivanovich"
But it returns me both results where fullNames are:
"fullName": "Ivanov Ivan Ivanovich"
"fullName": "Ivanov Gleb Glebovich"
It happens because both of these results contain “Ivan” as a part of first “Ivanov”.
Is there a way to modify my query to specify that order of appearance is important?
This application is just a phone book and I want to allow users to search contacts just specifying second name and two first letters of last name and second name.