We are migrating our Lucene based search codebase to Elasticsearch. The major problem we encountered is how we should migrate our QueryParser
s.
In our old solution, the QueryParsers take in a human input query string, and transform that to Lucene's Query
object, which is then fed into Lucene's IndexSearcher. However, in Elasticsearch we don't directly interact with IndexSearcher, instead we can only build the queries in the client side using Query DSL and send the JSON to Elasticsearch server. Elasticsearch server then (possibly) rewrites/analyses the JSON query to build a Lucene query.
To make use of our existing and sophisticated logic in QueryParsers, we decided that we can stick to our old approach by:
- Explicitly tell Elasticsearch to NOT analyze any query in the search time.
- Do ALL the query related analysis (tokenizing, synonym, etc) in the Java client.
- Believe that Elasticsearch's Query DSL is kind of a one-to-one mapping to Lucene's
Query
Don't worry about the scoring process, we are writing our scorer scripts as a Elasticsearch plugin.
The questions are:
- Is this approach feasible?
- What are the potential problems in doing so?
- What is the best practice?
Thanks in advance!