Skip to content

Instantly share code, notes, and snippets.

@karmi
Created April 20, 2011 13:32
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save karmi/931339 to your computer and use it in GitHub Desktop.
Save karmi/931339 to your computer and use it in GitHub Desktop.
Highligthing in ElasticSearch; number_of_fragments bug
# (Re)create the index
curl -X DELETE "http://localhost:9200/highlight"
curl -X PUT "http://localhost:9200/highlight"
# 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 just as he drank, the Fox informed him of the difficulty they were both in and suggested a scheme for their common escape. \"If,\" said he, \"you will place your forefeet upon the wall and bend your head, I will run up your back and escape, and will help you out afterwards.\" The Goat readily assented and the Fox leaped upon his back. Steadying himself with the Goat horns, he safely reached the mouth of the well and made off as fast as he could. When the Goat upbraided him for breaking his promise, he turned around and cried out, \"You foolish old fellow! If you had as many brains in your head as you have hairs in your beard, you would never have gone down before you had inspected the way up, nor have exposed yourself to dangers from which you had no means of escape.\" Look before you leap." }'
curl -X POST "http://localhost:9200/highlight/_refresh"
# Queries
curl -X POST "http://localhost:9200/highlight/_search?pretty=true" -d '
{
"query" : {
"query_string" : { "query" : "fox"}
},
"highlight" : {
"fields" : {
"body" : {}
}
}
}'
echo
echo '-----'
echo
# Queries
curl -X POST "http://localhost:9200/highlight/_search?pretty=true" -d '
{
"query" : {
"query_string" : { "query" : "fox"}
},
"highlight" : {
"fields" : {
"body" : {"number_of_fragments" : 0}
},
"pre_tags" : ["<strong class=\"highlight\">"],
"post_tags" : ["</strong>"]
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment