Answer the question
In order to leave comments, you need to log in
How to do Autocomplete search with ElasticSearch?
Who can share an example of how to do an Autocomplete search using ElasticSearch? Do I need to use AJAX to send a GET request to the desired URL? Diagram is not clear at all.
Answer the question
In order to leave comments, you need to log in
I've personally used the Completion Suggester , which is fine if you know in advance what queries the user might be looking for. In my case, these were the names of settlements.
The general scheme is something like this. Depending on the framework you use and the php client for elastic, you can add the code yourself. I'll also omit the details about setting up Russian morphology if you need it, because. this is an even broader issue.
1. Create a separate index for the suggester
2. Create a separate type in this index and give it the correct mapping
curl -XPUT http://localhost:9200/typeahead/locality/_mapping -d '{
"properties": {
"suggest": {
"type": "completion"
}
}
}'
curl -XPOST http://localhost:9200/typeahead/locality/ -d '{
"suggest": {
"output": "Москва, Московская область, Россия",
"input": ["Москва"]
}
}'
curl -XPOST http://localhost:9200/typeahead/locality/ -d '{
"suggest": {
"output": "Новосибирск, Новосибирская область, Россия",
"input": ["Новосибирск"]
}
}'
curl -XGET http://localhost:9200/typeahead/_suggest -d '{
"locality-suggest" : {
"text" : "Новосиб",
"completion" : {
"field" : "suggest"
}
}
}'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question