I'm looking for a better way.
I have an arbitrary number of input terms (let's say they are last names) from the user. I want to perform a prefix search on each one and boost score for any matches.
The not-analyzed prefix query is what I'm using now -- see example below -- however I'm also taking on the responsibility of what an analyzer would otherwise do by creating custom programming to split apart the input terms on whitespace, trimming, lower-casing them, and then constructing a series of prefix queries with the tokens to boost scoring like so.
- Example input is a bunch of last names like "Smith, Rodriguez, ROBERTS, doe".
Then my programming parses them into tokens and lowercases them into:
smith
rodriguez
roberts
doeFinally I construct multiple prefix queries to boost the score like so
"should": [ { "dis_max" : { "tie_breaker": 1, "boost": 3, "queries": [ { "prefix" : { "surname": "doe"} }, { "prefix" : { "surname": "rob"} }, { "prefix" : { "surname": "rod"} }, { "prefix" : { "surname": "smi"} } ] } } ],
I can't help but think I'm doing this in an inefficient manner and that elasticsearch might provide smarter features that I don't know about. I wish for an analyzed form of the prefix query to make my life easy. For example it would be ideal to pass input verbatim for analysis to an elastic query like so "someAnalyzedPrefix": {"surname": "smith rodriguez roberts doe", prefix_length: 3}
I'm dreaming a bit here, but you get the gist of the fact I'm looking for a more curt solution.
I wonder if any other kinds of queries can effect the same outcome while taking responsibility for analysis.
Suggestions for improvement are all welcome, otherwise I'll be sticking with the pattern above as it does meet the need although not necessarily beautifully.