Skip to content

Instantly share code, notes, and snippets.

@aq1018
Created February 22, 2014 01:35
Show Gist options
  • Save aq1018/9147301 to your computer and use it in GitHub Desktop.
Save aq1018/9147301 to your computer and use it in GitHub Desktop.
ElasticSearch Autocomplete example
curl -XDELETE 'http://localhost:9200/media'
curl -XPUT 'http://localhost:9200/media' -d'
{
"mappings": {
"movie": {
"properties": {
"genre": {
"type": "string",
"analyzer": "keyword"
},
"release_date": {
"type": "date"
},
"mpaa_rating": {
"type": "string",
"analyzer": "keyword"
},
"title": {
"fields": {
"autocomplete": {
"type": "string",
"analyzer": "autocomplete"
},
"title": {
"type": "string"
}
},
"type": "multi_field"
}
}
}
},
"settings": {
"analysis": {
"filter": {
"autocomplete_ngram": {
"type": "edgeNGram",
"max_gram": 15,
"min_gram": 1
}
},
"analyzer": {
"autocomplete": {
"filter": [
"standard",
"lowercase",
"stop",
"kstem",
"autocomplete_ngram"
],
"type": "custom",
"tokenizer": "standard"
}
}
}
}
}'
curl -XPOST http://localhost:9200/media/movie/the_lego_movie -d '{
"title": "The Lego Movie",
"release_date": "2014-02-07",
"running_time": 100,
"mpaa_rating": "PG",
"genre": ["animation", "family", "comedy", "advanture", "action"]
}'
curl -XPOST 'http://localhost:9200/_flush'
curl -XPOST http://localhost:9200/media/movie/_search?pretty -d '{
"query":{
"match":{
"title.autocomplete": "l"
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment