9

I have partial matching of words working with ngrams. How can I modify the mapping to always favor exact matches over ngram tokens? I do not want to modify the query. One search box will search multiple types, each with their own fields.

For example, lets say I'm searching job titles, one person has a title of "field engineer", the other a title of "engine technician". If a user searches for "engine", I'd want ES to return the latter as more relevant.

I'm using this mapping almost verbatim: https://stackoverflow.com/a/19874785/978622 -Exception: I'm using an ngram with min of 3 and max of 11 instead of edge ngram

Is it possible to apply a boost/function score to an analyzer? If so I'll apply both the "full_name" and "partial_name" analyzers to my index as well and boost the first.

Edit: I'm using ElasticSearch 1.1.1 and Nest 1.0.0 beta

Community
  • 1
  • 1
Brandon
  • 1,058
  • 1
  • 18
  • 42
  • Are you restricted to 1 result per query? Without knowing ES, I'd suggest that you leave it, return bot and let the user select. – marekful May 15 '14 at 19:04
  • No, it returns a list as large as I specify. But think on a bigger scale. My index has 20000 items. The example I gave will happen on a much larger scale. I can't just let the user choose. – Brandon May 15 '14 at 19:06
  • You can present the user with a number of choices, e.g. 10 (still not worrying about ordering, because users can select anyway). If the desired result is not listed, user narrows. This is how it works... – marekful May 15 '14 at 19:09
  • @MarcellFülöp This misses the point of the question. Rather than ignore the problem, I'd like to fix it. Leaving it to users is not a fix. – Brandon May 15 '14 at 19:18
  • That's why I'm not giving an answer just trying to suggest that perhaps you are unnecessarily overcomplicating. I understand the problem and what you want, but I don't think it is a problem or that it's worth the effort to bother with the ordering of those few results unless there is a really good reason which you haven't come up with yet. – marekful May 15 '14 at 19:32

1 Answers1

8

I don't believe there is anyway to apply boosting to an analyzer as you're suggesting.

One thing you can try, is to use the multi field type in your mapping. You could then apply your partial_name analyzer to one version of the field, and your full_name analyzer to the other version.

With this mapping, you could query both fields differently, but combined (perhaps in a bool query), and apply a boost to the query that is being conducted on the full_name analyzed field.

Greg Marzouka
  • 3,315
  • 1
  • 20
  • 17
  • I believe this is what you're saying. I did use multifield. On the index side of things each field had 2 fields. One for a full match analyzer one that had an "ngram" suffix with an ngram analyzer. On the query side I used a simplequerystring using "OnFieldsWithBoost" Any full fields I searched had a .1 higher boost than any ngram fields searched. – Brandon Jul 08 '14 at 20:42
  • Yup, that's essentially what I was saying. I'm assuming it worked out? – Greg Marzouka Jul 08 '14 at 21:28
  • It took a little experimenting to get the weights correct without overweighting any specific field, but yes it worked perfect. – Brandon Jul 09 '14 at 12:50
  • 2
    The link is dead. [Try this](https://www.elastic.co/guide/en/elasticsearch/reference/1.7/_multi_fields.html#_multi_fields) – emilebaizel Nov 06 '15 at 17:50
  • what is the analyzer that I should use for exact matching? – cegprakash Jun 30 '17 at 00:58