I am trying to create an auto-complete feature using elastic search for my e-commerce database. It has an index of products each of which is identified by attributes like color, size, category, bu.
What I want is when the user searches for "Re" it should suggest "Red", "Regular", "Reddish" and so on sorted by the count of products that have that attribute. So if 100 documents have "Red" and 50 have "Reddish", "Red" will appear on top. Since I am suggesting, I want the second meaningful word to go along with it as well. For e.g. along with "Red" as a suggestion, I want to show "Red Dress", "Red Shirt" and so on. The logic again is to find all the documents that have the maximum number of documents for the second word.
For e.g, if a user searches for "Re", the suggestion will be "Red Dress", followed by "Red Shirt" and then "Reddish Skirt". It will find all that starts with "Re" sorted by count, then find all the documents that have "Red" and suggest "Dress" before "Shirt" assuming "Dress" has more count than "Shirt".
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…