Skip to content

Instantly share code, notes, and snippets.

@imotov
Created April 11, 2012 10:11
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 imotov/2358376 to your computer and use it in GitHub Desktop.
Save imotov/2358376 to your computer and use it in GitHub Desktop.
Specific analyzer per document repro
echo "Deleting the test index"
curl -XDELETE localhost:9200/test-idx
echo
echo "Creating the test index"
curl -XPUT localhost:9200/test-idx -d '{
"settings": {
"index" : {
"number_of_shards" : 1,
"number_of_replicas" : 0
}
}
}'
echo
echo "Setting mapping"
curl -XPUT localhost:9200/test-idx/content/_mapping -d '{"content": {
"_source" : {"enabled" : true},
"_uid" : {"index" : "no", "store" : "no"},
"_id" : {"index" : "no", "store" : "yes"},
"_analyzer" : {"path" : "my_anal", "index" : "no"},
"_index" : {"enabled" : true, "index" : "no", "store" : "yes"},
"properties" : {
"body" : {"type" : "string",
"store" : "yes",
"index" : "analyzed",
"boost" : 1.0,
"term_vector" : "with_positions_offsets"
}}
}}'
echo
echo "----------------------------------------------------------------------"
echo "Indexing a record with the standard analyzer"
curl -XPUT localhost:9200/test-idx/content/1 -d '{"body" : "this is testing", "my_anal" : "standard"}'
echo
curl -XPOST localhost:9200/test-idx/_refresh
echo
echo "Should get back one token 'testing'"
curl -XGET localhost:9200/test-idx/_search\?pretty=true -d '{
"query": {
"query_string": {
"query": "_id:1"
}
},
"facets": {
"terms1": {
"terms": {
"field": "body"
}
}
}
}'
echo
echo "----------------------------------------------------------------------"
echo "Indexing a record with the keyword analyzer"
curl -XPUT localhost:9200/test-idx/content/2 -d '{"body" : "this is testing", "my_anal" : "keyword"}'
echo
curl -XPOST localhost:9200/test-idx/_refresh
echo
echo "Should get back one token 'this is testing'"
curl -XGET localhost:9200/test-idx/_search\?pretty=true -d '{
"query": {
"query_string": {
"query": "_id:2"
}
},
"facets": {
"terms1": {
"terms": {
"field": "body"
}
}
}
}'
echo
echo "----------------------------------------------------------------------"
echo "Indexing a record with the snowball analyzer"
curl -XPUT localhost:9200/test-idx/content/3 -d '{"body" : "this is testing", "my_anal" : "snowball"}'
echo
curl -XPOST localhost:9200/test-idx/_refresh
echo
echo "Should get back one token 'test'"
curl -XGET localhost:9200/test-idx/_search\?pretty=true -d '{
"query": {
"query_string": {
"query": "_id:3"
}
},
"facets": {
"terms1": {
"terms": {
"field": "body"
}
}
}
}'
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment