Skip to content

Instantly share code, notes, and snippets.

@jprante
Created May 9, 2014 21:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jprante/9f7523bb59ea654a3931 to your computer and use it in GitHub Desktop.
Save jprante/9f7523bb59ea654a3931 to your computer and use it in GitHub Desktop.
Highlighting with copy_to in Elasticsearch
curl -XDELETE 'localhost:9200/test'
curl -XPUT 'localhost:9200/test/' -d '
{
"mappings" : {
"_default_": {
"properties" : {
"name" : {
"type" : "string",
"store" : "yes"
},
"name_de" : {
"type" : "string",
"analyzer" : "german",
"copy_to" : "name"
},
"name_en" : {
"type" : "string",
"analyzer" : "english",
"copy_to" : "name"
}
}
}
}
}
'
curl -XPUT 'localhost:9200/test/data/1' -d '
{
"name_de" : "Köln",
"name_en" : "Cologne"
}
'
curl -XPUT 'localhost:9200/test/data/2' -d '
{
"name_de" : "München",
"name_en" : "Munich"
}
'
curl -XGET 'localhost:9200/test/_refresh'
curl -XGET 'localhost:9200/test/data/_search?pretty' -d '
{
"query" : {
"match": {
"name": {
"query": "Köln"
}
}
},
"highlight": {
"pre_tags": [
"<em>"
],
"post_tags": [
"</em>"
],
"fields": {
"name": {}
}
}
}'
curl -XGET 'localhost:9200/test/data/_search?pretty' -d '
{
"query" : {
"match": {
"name": {
"query": "Munich"
}
}
},
"highlight": {
"pre_tags": [
"<em>"
],
"post_tags": [
"</em>"
],
"fields": {
"name": {}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment