NGram Analyzer in ElasticSearch

  • Download Gist
elastic_search_ngram_analyzer_for_urls.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
# ========================================
# 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.