Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save fmpwizard/3803180 to your computer and use it in GitHub Desktop.
Save fmpwizard/3803180 to your computer and use it in GitHub Desktop.
NGram Analyzer in ElasticSearch
# ========================================
# Testing n-gram analysis in ElasticSearch
# ========================================
curl -X DELETE localhost:9200/test
curl -X PUT localhost:9200/test -d '
{
"settings" : {
"index" : {
"analysis" : {
"analyzer" : {
"part_number_analyzer" : {
"type" : "custom",
"tokenizer" : "keyword",
"filter" : ["part_number_edgeNGram", "word_filter", "lowercase"]
}
},"filter" : {
"part_number_edgeNGram" : {
"type" : "edgeNGram",
"min_gram" : 4,
"max_gram" : 30,
"side" : "front"
},"lowercase" : {
"type" : "lowercase"
},
"word_filter": {
"type": "word_delimiter",
"generate_word_parts" : "false",
"generate_number_parts" : "false",
"split_on_numerics" : "false",
"split_on_case_change" : "false",
"preserve_original" : "true"
}
}
}
}
},
"mappings": {
"main": {
"properties": {
"part_number": {
"type": "string",
"index_analyzer": "part_number_analyzer",
"search_analyzer": "keyword",
"boost": 10
}
}
}
}
}
'
curl -X POST "http://localhost:9200/test/main" -d '{ "part_number" : "PA2829U" }'
curl -X POST "http://localhost:9200/test/main" -d '{ "part_number" : "5W298" }'
curl -X POST "http://localhost:9200/test/main" -d '{ "part_number" : "12345-78912345" }'
curl -X POST "http://localhost:9200/test/_refresh"
curl "http://localhost:9200/test/_analyze?text=PA2829U&analyzer=part_number_analyzer&pretty=true"
URLS='
http://localhost:9200/test/_search?q=part_number:pa2829
http://localhost:9200/test/_search?q=part_number:PA2829
http://localhost:9200/test/_search?q=part_number:PA111
http://localhost:9200/test/_search?q=part_number:5W29
http://localhost:9200/test/_search?q=part_number:12345-78912345
'
for url in ${URLS}
#for url in "nada"
do
echo; echo; echo ">>> ${url}"
if which open &> /dev/null; then
open "${url}&pretty=true"
fi
curl "${url}&pretty=true"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment