0

I want to implement autocomplete with elasticsearch and I'm unable to do it. I want something like this question here. I tried the suggested answers but in vain. I want to have something like the following :

I have used complete suggester to handle such scenarios .Since order of search is important .

A simple example would be having these documents indexed using standard analyzer:

A :Source B :Destination

1. Bus from Alpha to Beta 
2. Morning Bus from Alpha to Beta 
3. Bus Fare from Beta to Alpha
4. Cheapest Bus Fare from Beta via Cita to Alpha

I could query for "Alp" and this would return me all documents, including the third and fourth one.I want to retrieve only documents 1 and 2 .If I query "Bet"or "Beta" only documents 3 and documents 4 should return.Slop is not specific to 1 or 2 it can be anything .

Please suggest the index settings properties for this and share the code

What if I wanted to only retrieve the documents which have the terms in this specific order? Can I form a query that would do that for me?

Considering it is possible for phrases by simply quoting the text: "Bus Alp" ,"Bus Alph"(retrieve 1st and 2nd docs) it feels to me like there should be a way of preserving the order for multiple terms that aren't adjacent. I have used complete suggester .But it doesnot seem to solve all the use cases . Please suggest ?

user2019
  • 1
  • 1
  • Check out the accepted answer to [this question](https://stackoverflow.com/questions/26634595/preserving-order-of-terms-in-elasticsearch-query). You can take that approach and remove the optional `slop` factor, and I think this will give you the matching behaviour you're looking for. – avik Aug 01 '19 at 13:09
  • Possible duplicate of [Preserving order of terms in ElasticSearch query](https://stackoverflow.com/questions/26634595/preserving-order-of-terms-in-elasticsearch-query) – avik Aug 01 '19 at 13:10
  • @avik:I saw this solution .But there is usage of slop .Slopeness can vary from query to query .How to handle such scenarios? – user2019 Aug 01 '19 at 16:30
  • Try the `span_near` query _without_ the`slop` setting – avik Aug 01 '19 at 22:23
  • Please share the sample query – user2019 Aug 02 '19 at 05:25
  • @avik:I have shared the detailed explanation of my requirement .Please share the solution this – user2019 Aug 02 '19 at 06:39

0 Answers0