I've implemented autocomplete in Elasticsearch using edge-ngrams. Everything is working correctly, but there is a strange case which my implementation is not smart enough to handle.
Suppose I have indexed two documents,
Green Dragon
Green Griffin
and I type
green gr
the results I get back are
Green Dragon
Green Griffin
I am using a "match" query with the "and" operator, so every term in the query must match in order for the query to match. The reason Green Dragon is returned is because the query term "green" matches "Green" and the query term "gr" also matches "Green". Of course I want to exclude Green Dragon from the results.
It seems like to solve this problem Elasticsearch would need to keep track of which tokens in the index have been matched and not reuse them. Is there any way to do this within Elasticsearch?