Giving good results to bad queries is a tricky business.
I don't mean to say your Query DSL is bad but what the original user provides to you is plain text rather than a structured set of choices (color:red
, department:rings
etc).
When we have unstructured queries there are a default set of ranking heuristics that can apply to searches:
- The more words that match the better
- Rare words are better than common words
- Short documents are better than long ones
- Docs that repeat words are better than those that have them only once.
Your "explain" output does not detail the matches on the nested documents but I imagine rule #2 is applying most here in that the word name:Zirconia
and type:Zirconia
are seen as very rare and therefore interesting. The words color:red
and category:rings
are quite common and therefore seen as boring (almost as boring as text:with
). Another issue with the rareness heuristic is that multi-field searches can favour precisely the wrong field - red
is seen as more interesting when found in any field other than color:red
where it is commonplace. The "cross_fields" mode of multi-match attempts to overcome this wrong-field bias but it uses subtle per-word+field scoring tweaks that are undone if you choose to apply those global boosts at a field level.
Ultimately you know more about user-intent than a default set of ranking heuristics will ever do. You could consider pre-processing the query to identify structure where it is missing and turn a bad query which is just a bag of words into a more structured one. e.g. spotting the colors or departments in the text and pulling those out into more structured clauses or "did you mean?" suggestions. The Percolate api may be a good way of implementing this pre-processor with "things-to-look-for in user queries".