What you are describing should naturally happen. Lucene is the search engine that underpins elasticsearch and it uses the following heuristics when searching:
Docs containing all of the provided search terms are better than those with few
Docs that mention the terms multiple times are better than those with only one.
Shorter documents are better than very long ones.
Matches on rare search terms are better than those only matching common terms.
These ranking factors have names (coord, TF, length norm, IDF) and the scores can be seen using the explain api [1]
Presumably "strawberry chocolate cake" is something an end user types in so the question is how to take that string and turn it into some JSON elasticsearch can run with. The answer is there are several options and you don't have to settle on one. You could, for example, express it as a logical query "a OR b OR c" but also simultaneously run it as a phrase "a NEXTTO b NEXTTO c" (this is pseudo code). The first query is very lax, matching any of the given words while the second is very strict and needs all the words in that exact order. Of course documents that match both of these query clauses will score more highly than those that match only one.
The lax and tight query clauses are nested in a bool expression as elements in a should array :
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.