I am quite new for elasticsearch and reading elasticsearch related documents from few days. I am creating a contact list search for my application, where contacts are stored in <lastname (nickname), firstname> format.
I am facing a problem while searching the name using java client.
for example few contacts in my application are:
Smith (Mik), Mike
Trav (Mik), John
Now, when I search the name with java client api, the search term split in tokens and return wrong results:
QueryBuilder qb = QueryBuilders.queryString("John Gomes*");
Expected Result: 0
Actual Result: "Smith, John", "Gomes, Madona" and "Trav (Mik), John"
QueryBuilder qb = QueryBuilders.queryString("Smi* John");
Expected Result: "Smith, John"
Actual Result: "Smith, John" , "Smith (Mik), Mike" and "Trav (Mik), John"
QueryBuilder qb = QueryBuilders.queryString("Gomes Madona");
Expected Result: "Gomes, Madona"
Actual Result: "Gomes, Madona" and "Fernandis, Madona"
This is heppening because search term split into two tokens and it's searching in result for 2 separate words.
I tried with "not_analyzed" in mapping for name field but it restricted me to search case sensitive and in record stored order only, but as per my usecase user can search with any order in name. In case of two or more words query I need to display exact results and in case of one word query I have to display results containing search term.
Please suggest how to get expected results. What config changes I need to do to get correct results.
Thanks in advance.