Synonyms in Elastic search

(Tania Gandhe) #1

Suppose I want to use the synonyms token filter and a synonyms text file during indexing i.e. apply the synonym token filter in the indexing analyzer, How do I assign a preference to the query being searched ?
For example my synonym text file contains :
dog, cat
If I search for cat, results with dog may appear first. How do I customize so that results with cat appear first and then results containing the synonyms (here dog )..

(Ivan Brusic) #2

This request cannot be done easily. Lucene does not differentiate between
the tokens found in the postings list. Both tokens are treated equally.

One possible solution is to index the same field twice, once with the
synonyms filter, the other without. You can then use a dismax query with
the same query as the clauses, just on different fields. Very kludgy. Using
a script with a function score would be even kludgier.



(system) #3