I am having a challenge with multi words synonym related queries. E.g I have the following format of synonym:
Spanish onion, red onion
I have a document which contains words “onion red”. When I use multi match “cross_fields” searching with query “red onion”, or “Spanish onion”, it doesn’t return the above product. It looks like adding the synonym filter caused the problem. I tried to specify “slop”, however it didn’t work at all. Does anyone have any ideas?
You don't provide a lot of details with regards to how you have implemented these synonyms, but I'm assuming you're using the synonym_graph token filter in a search analyzer?
When you define multi-word synonyms using the synonym_graph token filter, those multi-words are then treated as phrases, even in a regular match query (or multi_match query). So, by defining spanish onion and red onion as synonyms, you will now no longer search for red OR onion, but for the phrase "red onion" (and its synonyms) instead. This is why you can't find your document.
As a way around this you could use a bool query that searches both with and without synonyms, by overriding the analyzer to be the standard analyzer in one of the queries. That would look something like this:
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.