Autocomplete using elasticsearch
' PUT /bank { "settings": { "analysis": { "filter": { "autocomplete_filter": { "type": "edge_ngram", "min_gram": 1, "max_gram": 10 } }, "analyzer": { "autocomplete": { "type": "custom", "tokenizer": "standard", "filter": [ "lowercase", "autocomplete_filter" ] } } } } } '
'GET /bank/_analyze?analyzer=autocomplete&text='swapnil pande' '
'PUT bank/account/_mapping { "account": { "properties": { "account_number": { "type": "long" }, "address": { "type": "string" }, "age": { "type": "long" }, "balance": { "type": "long" }, "city": { "type": "string" }, "email": { "type": "string" }, "employer": { "type": "string" }, "firstname": { "fields": { "autocomplete": { "type": "string", "index_analyzer": "autocomplete", "search_analyzer": "standard" }, "exact": { "type": "string", "index": "not_analyzed" } }, "type": "multi_field" }, "gender": { "type": "string" }, "lastname": { "type": "string" }, "state": { "type": "string" } } } }'
' curl -XPOST 'localhost:9200/bank/account/_bulk?pretty' --data-binary "@accounts.json" '
'GET /bank/account/_search { "query": { "term": { "firstname.autocomplete": "s" } }, "aggs":{ "autoResults":{ "terms":{ "field": "firstname.autocomplete", "size":5 } } } }'