If someones searches for 'ckd' it should only search for ckd and the phrase 'chronic kidney disease'
If someone searches for chronic kidney disease it should search for 'ckd' and chronic kidney disease both as a phrase and as conjoined terms so +chronic +kidney +disease anywhere in the document
Everything works great expect point 1, in order to get this to work I have to set auto_generate_synonyms_phrase_query to true but when I do this I lose the requirements in point 2 and lose the docs where the terms chronic, kidney and disease appear separately.
You are running into an interesting challenge with multi-word synonyms, and that is that if you use a multi-word query for a phrase that has been defined as a synonym, in a match query it will be treated as a phrase. This breaks the usual behavior of match queries, where each of the search terms is treated as being in a simple OR query.
The easiest way to work around this, is to use query time synonyms instead of index time synonyms (preferably using the synonym_graph token filter). This will allow you to rewrite your query to a bool query, that searches for the terms with synonyms and without synonyms at the same time. As a result, you will find documents containing synonyms as well as documents that contain the individual search terms.
So, given an index with the following settings and mappings:
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.