In my application, we have a search bar where a user can enter either first name, last name, ID, or an Email address. I am querying on User's data which is having the following fields, First Name, Last Name, ID, Email
For querying the first name, last name, and ID, I am querying like this-
{
"query":{
"query_string" : {"fields" : ["FName", "LName", "ID"], "query" : "Value entered by user*"}
}
}
For querying an Email address, I want an exact match and I am querying like this-
{
"query": {
"bool": {
"must": [{
"match": {
"Mail": "Value entered by user"
}
}]
}
}
}
I have two questions here-
- How can I combine the above two queries into one, that can provide me results of users whose First Name, Last name, ID, or Email matches with whatever is entered in the search bar?
- How to extract only those users whose First Name, Last Name, ID, and Email exist in the database. For eg., if a user's detail matches with the search text but if its Email address isn't in the database, I don't want to show it.