Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hukl/989073 to your computer and use it in GitHub Desktop.
Save hukl/989073 to your computer and use it in GitHub Desktop.
NGram Analyzer in ElasticSearch
curl -X DELETE localhost:9200/custom_analyzer_test
curl -X PUT localhost:9200/custom_analyzer_test -d '
{
"settings" : {
"index" : {
"number_of_shards" : 1,
"number_of_replicas" : 0,
"analysis" : {
"analyzer" : {
"url_analyzer" : {
"type" : "custom",
"tokenizer" : "lowercase",
"filter" : ["lowercase", "stop", "url_filter", "url_ngram"]
}
},
"filter" : {
"url_filter" : {
"type" : "stop",
"stopwords" : ["http", "https", ":", "/", ".", "html"]
},
"url_ngram" : {
"type" : "nGram"
}
}
}
}
},
"mappings": {
"url": {
"properties": {
"url": {
"type": "string",
"analyzer": "url_analyzer",
"boost": 10
},
"title": {
"type": "string",
"analyzer": "snowball",
"boost": 5
},
"description": {
"type": "string",
"analyzer": "snowball"
},
"tags": {
"type": "string",
"analyzer": "keyword"
}
}
}
}
}
'
curl -X POST "http://localhost:9200/custom_analyzer_test/url?refresh=true" -d '
{
"url" : "http://www.euruko2011.org",
"title" : "EURUKO 2011",
"description" : "The greatest Ruby conference in Europe!",
"tags" : ["ruby", "conference"]
}'
# curl "http://localhost:9200/custom_analyzer_test/_analyze?text=http://euruko2011.org/speakers.html&analyzer=url_analyzer"
curl "http://localhost:9200/custom_analyzer_test/_search?q=url:peak"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment