Is there any way to implement autofill and autogenerate results feature in Elasticsearch

Hi,

I'm trying to do a document search application using Elastic search(NEST client)[I'm indexing the word documents as an attachment as of now].
I would like to know if there is way to do an auto fill feature using ES.

Something like "As in when i type some text in search text box, it start returning results based on that few text. Similar to google."

TIA

You can use the suggest API or use edge ngrams based analyzers for that.

Hi David.
Thanks for the suggestion.
I was reading through Completion suggester (> https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html & https://www.elastic.co/blog/you-complete-me). While reading through, I got a doubt. While using this suggester, while indexing the document,do we have to give the output of the suggestion also? And also while working on attachments, how can I implement this suggester? TIA
TIA

Yeah. It probably won't work with attachments unless you do the text extraction on your side with Tika directly.

So you'd probably better use ngrams.

if I'm not wrong , ngrams are used for a different purpose.
for eg: lets say I'm indexing a word elastic, then it will index as e,el,ela,elas,elast,elasti, elastic. So when I try to search "el" it will give me this result. Isnt it?

But my purpose is to only suggest the as I type the keyword and on search button click, it should find as per the search query and the keyword. Can ngrams be used in this case also?

indeed. But once you get the 1st 10 more relevant documents, you can extract from their _source any field you want and display it to the user?
Or run an aggregation on a given non analyzed field and display that to the user?

Thanks david. But I'm already using "english" analyzer on the attachment's content field. So can this(ngram) be joined along with it? (like separate index analyzer and search analyzer).. I presume this one (the english analyzer is search analyzer in this case)

I think we support multi fields. So you could may be use that to index as well with ngrams.

I tried to do IIRC on scrutmydocs project but it was giving not so good results on the content field. Was making more sense on title.

thanks for the info david.. Yeah if im using ngrams i will be using it on title field where as english analyzer on the content field while search. does that make sense? am i thinking in the right direction?

Yes. But again (I think I already wrote that), using mapper attachments is not the ideal thing to do.

I definitely prefer:

  • Doing the extraction in my application with Tika, create the JSON document exactly as I want, apply analyzers, multifield, copy_to, whatever feature you want.

or

  • Wait for 5.0 and use ingest-attachment plugin.

mapper-attachments plugin will be removed in the future, probably in 5.1 or 6.0.
It's already marked as deprecated.

1 Like