Created
May 9, 2014 21:29
-
-
Save jprante/9f7523bb59ea654a3931 to your computer and use it in GitHub Desktop.
Highlighting with copy_to in Elasticsearch
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
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