Created
January 25, 2011 18:04
-
-
Save vhyza/795321 to your computer and use it in GitHub Desktop.
searching in multiple languages using different analyzers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Setup | |
curl -s -X DELETE 'http://localhost:9200/news_cs/' | |
curl -s -X DELETE 'http://localhost:9200/news_en/' | |
# Create Czech and English indices (databases) | |
curl -s -X PUT 'http://localhost:9200/news_cs/' | |
curl -s -X PUT 'http://localhost:9200/news_en/' | |
# Create mapping for Czech documents | |
curl -s -X PUT 'http://localhost:9200/news_cs/_mapping' -d ' | |
{ | |
"message" : { | |
"properties" : { | |
"body" : { | |
"type" : "multi_field", | |
"fields" : { | |
"body" : {"type" : "string", "index" : "analyzed", "analyzer" : "czech"}, | |
"exact" : {"type" : "string", "index" : "analyzed", "analyzer" : "keyword"} | |
} | |
} | |
} | |
} | |
}' | |
# Create mapping for English documents | |
curl -s -X PUT 'http://localhost:9200/news_en/_mapping' -d ' | |
{ | |
"message" : { | |
"properties" : { | |
"body" : { | |
"type" : "multi_field", | |
"fields" : { | |
"body" : {"type" : "string", "index" : "analyzed", "analyzer" : "snowball"}, | |
"exact" : {"type" : "string", "index" : "analyzed", "analyzer" : "keyword"} | |
} | |
} | |
} | |
} | |
}' | |
# Refresh indices | |
curl -s -X POST 'http://localhost:9200/news_cs/_refresh' | |
curl -s -X POST 'http://localhost:9200/news_en/_refresh' | |
# Create documents | |
curl -s -X POST 'http://localhost:9200/news_cs/message' -d '{"body":"stromeček"}' | |
curl -s -X POST 'http://localhost:9200/news_en/message' -d '{"body":"tree"}' | |
curl -s -X POST 'http://localhost:9200/news_cs/_refresh' | |
curl -s -X POST 'http://localhost:9200/news_en/_refresh' | |
# Create database "news" as an alias for "news_cs" and "news_en" | |
curl -s -X POST 'http://localhost:9200/_aliases' -d ' | |
{ | |
"actions" : [ | |
{ "add" : { "index" : "news_cs", "alias" : "news" } }, | |
{ "add" : { "index" : "news_en", "alias" : "news" } } | |
] | |
}' | |
# Search for phrase in English documents | |
curl -s -X GET 'http://localhost:9200/news/_search?pretty=true&q=body:trees' | |
curl -s -X GET 'http://localhost:9200/news/_search?pretty=true&q=body:tree' | |
# Search for phrase in Czech documents | |
curl -s -X GET 'http://localhost:9200/news/_search?pretty=true&q=body:strome%C4%8Dek' | |
curl -s -X GET 'http://localhost:9200/news/_search?pretty=true&q=body:strome%C4%8Dky' | |
# Search for exact phrase in English documents | |
curl -s -X GET 'http://localhost:9200/news/_search?pretty=true&q=body.exact:trees' | |
curl -s -X GET 'http://localhost:9200/news/_search?pretty=true&q=body.exact:tree' | |
# Search for exact phrase in Czech documents | |
curl -s -X GET 'http://localhost:9200/news/_search?pretty=true&q=body.exact:strome%C4%8Dek' | |
curl -s -X GET 'http://localhost:9200/news/_search?pretty=true&q=body.exact:strome%C4%8Dky' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment