Skip to content

Instantly share code, notes, and snippets.

@sxcong
sxcong / highlight.sh
Created May 20, 2016 03:18 — forked from karmi/highlight.sh
Highlighting query terms in ElasticSearch
# (Re)create the index
curl -X DELETE "http://localhost:9200/highlight"
curl -X PUT "http://localhost:9200/highlight" -d '
{ "mappings" : { "document" : { "properties" : { "body" : { "type" : "string", "analyzer" : "simple", "term_vector" : "with_positions_offsets" } } } } }
'
# Insert the data
curl -X POST "http://localhost:9200/highlight/document" -d '{ "body" : "The quick brown fox jumps over the lazy dog" }'
curl -X POST "http://localhost:9200/highlight/document" -d '{ "body" : "Lazy dog jumps over the quick brown fox" }'
curl -X POST "http://localhost:9200/highlight/document" -d '{ "body" : "A Fox one day fell into a deep well and could find no means of escape. A Goat, overcome with thirst, came to the same well, and seeing the Fox, inquired if the water was good. Concealing his sad plight under a merry guise, the Fox indulged in a lavish praise of the water, saying it was excellent beyond measure, and encouraging him to descend. The Goat, mindful only of his thirst, thoughtlessly jumped down, but ju