Skip to content

Instantly share code, notes, and snippets.

@scottrice10
Created September 10, 2013 01:01
Show Gist options
  • Select an option

  • Save scottrice10/6503689 to your computer and use it in GitHub Desktop.

Select an option

Save scottrice10/6503689 to your computer and use it in GitHub Desktop.
Here is a mapping using an ngram filter enabling Elasticsearch to search on word fragments, which is necessary for autocomplete. An alternative/addition to using an ngram filter (not shown here) would be to use a shingle filter, which additionally searches on phrase fragments.
curl -XPUT 'localhost:9200/doctors_index' -d '
{
"settings": {
"analysis": {
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": ["standard", "lowercase", "kstem", "edgeNGram"]
}
},
"filter" : {
"ngram" : {
"type": "edgeNGram",
"min_gram": 2,
"max_gram": 15
}
}
}
},
"mappings": {
"doctors" : {
"properties": {
"first_name": {
"type": "multi_field",
"fields": {
"first_name": {
"type": "string"
},
"post_title": {
"type": "string",
"analyzer": "post_title",
"similarity": "BM25"
},
"autocomplete": {
"analyzer": "autocomplete",
"type": "string"
}
}
}
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment