Skip to content

Instantly share code, notes, and snippets.

@fmpwizard
Created October 15, 2012 03:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fmpwizard/3890730 to your computer and use it in GitHub Desktop.
Save fmpwizard/3890730 to your computer and use it in GitHub Desktop.
search on description field
# ========================================
# Testing n-gram analysis in ElasticSearch
# ========================================
curl -X DELETE localhost:9200/test
curl -X PUT localhost:9200/test -d '
{
"settings" : {
"index" : {
"analysis" : {
"tokenizer" :{
"description_tokenizer" : {
"type" : "pattern",
"pattern" : "\\s+"
}
},
"analyzer" : {
"description_analyzer" : {
"type" : "custom",
"tokenizer" : "description_tokenizer",
"filter" : [ "edgeNgram_descr", "desc_word_filter", "lowercase"]
}
},
"filter" : {
"edgeNgram_descr" : {
"type" : "edgeNGram",
"min_gram" : 3,
"max_gram" : 255,
"side" : "front"
},
"desc_word_filter": {
"type": "word_delimiter",
"generate_word_parts" : "false",
"generate_number_parts" : "false",
"split_on_numerics" : "false",
"split_on_case_change" : "false",
"catenate_words" : "true",
"preserve_original" : "true"
}
}
}
}
},
"mappings": {
"main": {
"properties": {
"description": {
"type": "string",
"analyzer": "description_analyzer"
}
}
}
}
}
'
curl -X POST "http://localhost:9200/test/main" -d '{ "description" : "This keyBoard for Toshiba" }'
curl -X POST "http://localhost:9200/test/main" -d '{ "description" : "This keyboard for HP" }'
curl -X POST "http://localhost:9200/test/main" -d '{ "description" : "This battery li-ion toshiba" }'
curl -X POST "http://localhost:9200/test/main" -d '{ "description" : "This CD-RW/ DVD DRIVE Combo toshiba" }'
curl -X POST "http://localhost:9200/test/main" -d '{ "description" : "This cd-rw DVD DRIVE Combo toshiba" }'
curl -X POST "http://localhost:9200/test/main" -d '{ "description" : "8X DVD Drive" }'
curl -X POST "http://localhost:9200/test/main" -d '{ "description" : "6X DVD Drive" }'
curl -X POST "http://localhost:9200/test/main" -d '{ "description" : "Li-ION 6 Cells" }'
curl -X POST "http://localhost:9200/test/main" -d '{ "description2" : "Li-ION 6 Cells" }'
curl -X POST "http://localhost:9200/test/main" -d '{ "description" : "Li-ION 8 Cells" }'
curl -X POST "http://localhost:9200/test/main" -d '{ "description2" : "Li-ION 8 Cells" }'
curl -X POST "http://localhost:9200/test/_refresh"
curl "http://localhost:9200/test/_analyze?text=8x+mas+menos&analyzer=description_analyzer&pretty=true"
URLS='
http://localhost:9200/test/_search?q=description:key&default_operator=AND
http://localhost:9200/test/_search?q=description:key%20toshiba&default_operator=AND
http://localhost:9200/test/_search?q=description:toshiba&default_operator=AND
http://localhost:9200/test/_search?q=description:li-ion&default_operator=AND
http://localhost:9200/test/_search?q=description:cdrw&default_operator=AND
http://localhost:9200/test/_search?q=description:cd-rw&default_operator=AND
http://localhost:9200/test/_search?q=description:8x&default_operator=AND
http://localhost:9200/test/_search?q=description:6+Cells&default_operator=AND
'
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