Skip to content

Instantly share code, notes, and snippets.

@vhyza
Created May 24, 2011 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save vhyza/989867 to your computer and use it in GitHub Desktop.
Save vhyza/989867 to your computer and use it in GitHub Desktop.
# ========================================
# Testing multiple analyzers per field
# ========================================
# Setup
curl -s -X DELETE 'http://localhost:9200/news_test/'
# Create index with settings and mapping
curl -s -X PUT 'http://localhost:9200/news_test' -d '
{
"settings" : {
"index" : {
"analysis" : {
"analyzer" : {
"czech_ascii" : {
"type" : "custom",
"tokenizer" : "standard",
"filter" : ["asciifolding", "lowercase", "czech_stem"]
}
}
}
}
},
"mappings": {
"message" : {
"properties" : {
"body" : {
"type" : "multi_field",
"fields" : {
"body" : {"type" : "string", "index" : "analyzed", "analyzer" : "keyword" },
"body.czech" : {"type" : "string", "index" : "analyzed", "analyzer" : "czech" },
"body.czech.ascii" : {"type" : "string", "index" : "analyzed", "analyzer" : "czech_ascii"},
"body.english" : {"type" : "string", "index" : "analyzed", "analyzer" : "snowball"}
}
}
}
}
}
}'
# Refresh indices
curl -s -X POST 'http://localhost:9200/news_test/_refresh'
# Create documents
curl -s -X POST 'http://localhost:9200/news_test/message' -d '{"body":"stromeček"}'
curl -s -X POST 'http://localhost:9200/news_test/message' -d '{"body":"tree"}'
curl -s -X POST 'http://localhost:9200/news_test/_refresh'
echo '---Search for trees'
curl -s -X POST 'http://localhost:9200/news_test/_search?pretty=true' -d '{
"query":{
"query_string":{
"fields" : ["body.*"],
"query":"trees"
}
}
}'
echo '---Search for stromečky'
curl -s -X POST 'http://localhost:9200/news_test/_search?pretty=true' -d '{
"query":{
"query_string":{
"fields" : ["body.*"],
"query":"stromečky"
}
}
}'
echo '---Search for stromecky'
curl -s -X POST 'http://localhost:9200/news_test/_search?pretty=true' -d '{
"query":{
"query_string":{
"fields" : ["body.*"],
"query":"stromecky"
}
}
}'
echo '---Search for stromeček'
curl -s -X POST 'http://localhost:9200/news_test/_search?pretty=true' -d '{
"query":{
"query_string":{
"fields" : ["body.*"],
"query":"stromeček"
}
}
}'
echo '---Search for tree'
curl -s -X POST 'http://localhost:9200/news_test/_search?pretty=true' -d '{
"query":{
"query_string":{
"fields" : ["body.*"],
"query":"tree"
}
}
}'
echo '---Search for trees only in "exact" field'
curl -s -X POST 'http://localhost:9200/news_test/_search?pretty=true' -d '{
"query":{
"query_string":{
"fields" : ["body"],
"query":"trees"
}
}
}'
echo '---Search for stromečky in english field'
curl -s -X POST 'http://localhost:9200/news_test/_search?pretty=true' -d '{
"query":{
"query_string":{
"fields" : ["body.english"],
"query":"stromečky"
}
}
}'
echo '---Search for stromečky in czech.ascii field'
curl -s -X POST 'http://localhost:9200/news_test/_search?pretty=true' -d '{
"query":{
"query_string":{
"fields" : ["body.czech.ascii"],
"query":"stromečky"
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment