Skip to content

Instantly share code, notes, and snippets.

Created May 26, 2012 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2792582 to your computer and use it in GitHub Desktop.
Save anonymous/2792582 to your computer and use it in GitHub Desktop.
Index / Search Document with Punctuation in ElasticSearch
#!/bin/sh
HOST_ID="localhost"
echo "$HOST_ID"
echo $HOST_ID
echo
echo 'abbreviation_example'
# create template
curl -XPUT ${HOST_ID}:9200/_template/abbreviation_example_template -d '
{
"template" : "abbreviation_example_*",
"settings" : {
"number_of_shards" : 6,
"number_of_replicas" : 1,
"analysis" : {
"analyzer" : {
"standard" : {
"type" : "standard"
},
"custAnalyzer1" : {
"type" : "custom",
"tokenizer" : "custTokenizer",
"filter" : [
"myFilterStop", "myFilterLower", "myFilterSynonym", "myFilterStem"
]
}
},
"tokenizer" : {
"custTokenizer": {
"type" : "standard"
}
},
"filter" : {
"myFilterStop" : {
"type" : "stop"
},
"myFilterLower" : {
"type" : "lowercase"
},
"myFilterSynonym" : {
"type" : "synonym",
"synonyms" : [
"p.f., p.f, pf. => pf",
"universe, cosmos"
]
},
"myFilterStem" : {
"type" : "snowball",
"language" : "english"
}
}
}
},
"mappings" : {
"sample_type" : {
"_source" : { "enabled" : true, "compress": true },
"properties" : {
"a_field" : {
"type" : "multi_field",
"store" : "yes",
"include_in_all" : true,
"fields" : {
"a_field" : {"type" : "string", "index" : "analyzed", "analyzer" : "custAnalyzer1"},
"not_touched" : {"type" : "string", "index" : "not_analyzed"}
}
}
}
}
}
}
'
echo
curl -XPUT http://${HOST_ID}:9200/abbreviation_example_1/ -d '
{
}
'
echo
curl -XPOST http://$HOST_ID:9200/_aliases -d '
{
"actions" : [
{ "add" : { "index" : "abbreviation_example_1", "alias" : "abbreviation_example" } }
]
}'
echo
curl -XGET "${HOST_ID}:9200/abbreviation_example/_analyze?analyzer=custAnalyzer1&text=P.F.+Changs+Burgers"
echo
curl -XPUT http://${HOST_ID}:9200/abbreviation_example/sample_type/1 -d '{
"a_field" : "P.F. Changs Burgers"
}'
echo
curl -XGET "http://${HOST_ID}:9200/abbreviation_example/sample_type/_search?search_type=query_then_fetch&from=00&size=20&pretty=true" -d '
{
"fields": [
"a_field"
],
"query": {
"query_string": {
"default_field": "_all",
"query": "p.f.",
"default_operator": "AND"
}
}
}'
echo
echo 'p.f. works';
echo
sleep 2;
curl -XGET "http://${HOST_ID}:9200/abbreviation_example/sample_type/_search?search_type=query_then_fetch&from=00&size=20&pretty=true" -d '
{
"fields": [
"a_field"
],
"query": {
"query_string": {
"default_field": "_all",
"query": "p.f",
"default_operator": "AND"
}
}
}'
echo;
echo 'p.f works';
echo
sleep 2;
curl -XGET "http://${HOST_ID}:9200/abbreviation_example/sample_type/_search?search_type=query_then_fetch&from=00&size=20&pretty=true" -d '
{
"fields": [
"a_field"
],
"query": {
"query_string": {
"default_field": "_all",
"query": "pf.",
"default_operator": "AND"
}
}
}'
echo;
echo 'p.f doesnt work but Id like it to';
echo
sleep 2;
curl -XGET "http://${HOST_ID}:9200/abbreviation_example/sample_type/_search?search_type=query_then_fetch&from=00&size=20&pretty=true" -d '
{
"fields": [
"a_field"
],
"query": {
"query_string": {
"default_field": "_all",
"query": "pf",
"default_operator": "AND"
}
}
}'
echo;
echo 'pf doesnt work but Id like it to';
echo
sleep 2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment