Skip to content

Instantly share code, notes, and snippets.

@karmi
Forked from vhyza/elasticsearch_mapping.sh
Created January 26, 2011 09:05
Show Gist options
  • Save karmi/796446 to your computer and use it in GitHub Desktop.
Save karmi/796446 to your computer and use it in GitHub Desktop.
Mappings for different languages in ElasticSearch indices
# Setup
curl -X DELETE 'http://localhost:9200/news_cs/'
curl -X DELETE 'http://localhost:9200/news_en/'
# Create Czech and English indices (databases)
curl -X PUT 'http://localhost:9200/news_cs/'
curl -X PUT 'http://localhost:9200/news_en/'
# Create mapping for Czech documents
curl -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 -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 -X POST 'http://localhost:9200/news_cs/_refresh'
curl -X POST 'http://localhost:9200/news_en/_refresh'
# Create documents
curl -X POST 'http://localhost:9200/news_cs/message' -d '{"body":"stromeček"}'
curl -X POST 'http://localhost:9200/news_en/message' -d '{"body":"tree"}'
curl -X POST 'http://localhost:9200/news_cs/_refresh'
curl -X POST 'http://localhost:9200/news_en/_refresh'
# Create database "news" as an alias for "news_cs" and "news_en"
curl -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 -X GET 'http://localhost:9200/news/_search?pretty=true&q=body:trees'
curl -X GET 'http://localhost:9200/news/_search?pretty=true&q=body:tree'
# Search for phrase in Czech documents
curl -X GET 'http://localhost:9200/news/_search?pretty=true&q=body:strome%C4%8Dek'
curl -X GET 'http://localhost:9200/news/_search?pretty=true&q=body:strome%C4%8Dky'
# Search for exact phrase in English documents
curl -X GET 'http://localhost:9200/news/_search?pretty=true&q=body.exact:trees'
curl -X GET 'http://localhost:9200/news/_search?pretty=true&q=body.exact:tree'
# Search for exact phrase in Czech documents
curl -X GET 'http://localhost:9200/news/_search?pretty=true&q=body.exact:strome%C4%8Dek'
curl -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