Skip to content

Instantly share code, notes, and snippets.

@vhyza
Created January 25, 2011 18:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save vhyza/795321 to your computer and use it in GitHub Desktop.
Save vhyza/795321 to your computer and use it in GitHub Desktop.
searching in multiple languages using different analyzers
# 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