Skip to content

Instantly share code, notes, and snippets.

@jprante
Created November 1, 2013 18:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jprante/7270193 to your computer and use it in GitHub Desktop.
Save jprante/7270193 to your computer and use it in GitHub Desktop.
Demo of artist synonyms with special character escaping
curl -XDELETE 'localhost:9200/test'
rm /tmp/synonyms.txt
echo "kesha, ke\$ha" >> /tmp/synonyms.txt
echo "chk chk chk, !!!" >> /tmp/synonyms.txt
curl -XPUT 'localhost:9200/test' -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"artist" : {
"tokenizer" : "whitespace",
"filter" : [ "lowercase", "synonym", "asciifolding" ]
}
},
"filter" : {
"synonym" : {
"type" : "synonym",
"synonyms_path" : "/tmp/synonyms.txt"
}
}
}
},
"mappings" : {
"docs" : {
"properties" : {
"name" : { "type" : "string", "analyzer" : "artist" }
}
}
}
}
'
curl -XPUT 'localhost:9200/test/docs/1' -d '
{
"name": "kesha"
}
'
curl -XPUT 'localhost:9200/test/docs/2' -d '
{
"name": "chk chk chk"
}
'
curl -XPUT 'localhost:9200/test/docs/3' -d '
{
"name": "ke$ha"
}
'
curl -XPUT 'localhost:9200/test/docs/4' -d '
{
"name": "!!!"
}
'
curl -XGET 'localhost:9200/_refresh'
echo
curl -XGET 'localhost:9200/test/_analyze?pretty&analyzer=artist&text=kesha'
echo
curl -XGET 'localhost:9200/test/_analyze?pretty&analyzer=artist&text=ke%24ha'
curl -XGET 'localhost:9200/test/docs/_search?pretty' -d '
{
"query" : {
"match" : {
"name" : "kesha"
}
}
}
'
curl -XGET 'localhost:9200/test/docs/_search?pretty' -d '
{
"query" : {
"match" : {
"name" : "ke$ha"
}
}
}
'
echo
curl -XGET 'localhost:9200/test/_analyze?pretty&analyzer=artist&text=chk%20chk%20chk'
echo
curl -XGET 'localhost:9200/test/_analyze?pretty&analyzer=artist&text=%21%21%21'
curl -XGET 'localhost:9200/test/docs/_search?pretty' -d '
{
"query" : {
"match" : {
"name" : "chk chk chk"
}
}
}
'
curl -XGET 'localhost:9200/test/docs/_search?pretty' -d '
{
"query" : {
"match" : {
"name" : "!!!"
}
}
}
'
curl -XGET 'localhost:9200/test/docs/_search?pretty&q=name%3A%5C%21%5C%21%5C%21'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment