Skip to content

Instantly share code, notes, and snippets.

@imotov
Created November 22, 2012 03:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save imotov/5af5db1b08784ddf9724 to your computer and use it in GitHub Desktop.
Save imotov/5af5db1b08784ddf9724 to your computer and use it in GitHub Desktop.
curl -XDELETE localhost:9200/test-idx
curl -XPUT localhost:9200/test-idx -d '{
"settings" :{
"index": {
"number_of_shards": 1,
"number_of_replicas": 0
}
},
"mappings": {
"doc": {
"properties": {
"sentence" : {
"type": "string",
"position_offset_gap": 256
}
}
}
}
}'
echo
curl -XPUT localhost:9200/test-idx/doc/hobbit -d '{
"sentence": [
"In a hole in the ground there lived a hobbit.",
"Not a nasty, dirty, wet hole, filled with the ends of worms and an oozy smell, nor yet a dry, bare, sandy hole with nothing in it to sit down on or to eat: it was a hobbit-hole, and that means comfort.",
"It had a perfectly round door like a porthole, painted green, with a shiny yellow brass knob in the exact middle.",
"The door opened on to a tube-shaped hall like a tunnel: a very comfortable tunnel without smoke, with panelled walls, and floors tiled and carpeted, provided with polished chairs, and lots and lots of pegs for hats and coats – the hobbit was fond of visitors.",
"The tunnel wound on and on, going fairly but not quite straight into the side of the hill – The Hill, as all the people for many miles round called it – and many little round doors opened out of it, first on one side and then on another.",
"No going upstairs for the hobbit: bedrooms, bathrooms, cellars, pantries (lots of these), wardrobes (he had whole rooms devoted to clothes), kitchens, dining-rooms, all were on the same floor, and indeed on the same passage.",
"The best rooms were all on the left-hand side (going in), for these were the only ones to have windows, deep-set round windows looking over his garden, and meadows beyond, sloping down to the river."
]
}'
echo
curl -XPUT localhost:9200/test-idx/doc/hitchhiker -d '{
"sentence": [
"Far out in the uncharted backwaters of the unfashionable end of the western spiral arm of the galaxy lies a small, unregarded yellow sun.",
"Orbiting this at a distance of roughly 92 million miles is an utterly insignificant little blue-green planet whose ape-descended life forms are so amazingly primitive that they still think digital watches are a pretty neat idea.",
"This planet has - or rather had - a problem, which was this: most of the people on it were unhappy for pretty much of the time.",
"Many solutions were suggested for this problem, but most of these were largely concerned with the movements of small green pieces of paper, which is odd because on the whole it wasn'\''t the small green pieces of paper that were unhappy.",
"And so the problem remained; lots of the people were mean, and most of them were miserable, even the ones with digital watches."
]
}'
echo
curl -XPOST localhost:9200/test-idx/_refresh
echo
echo "far ... small"
curl "localhost:9200/test-idx/doc/_search?pretty=true" -d '{
"query": {
"span_near" : {
"clauses" : [
{ "span_term" : { "sentence" : "far" } },
{ "span_term" : { "sentence" : "small" } }
],
"slop" : 255,
"in_order" : true,
"collect_payloads" : false
}
},
"fields": []
}'
echo
echo "tunnel ... doors"
curl "localhost:9200/test-idx/doc/_search?pretty=true" -d '{
"query": {
"span_near" : {
"clauses" : [
{ "span_term" : { "sentence" : "tunnel" } },
{ "span_term" : { "sentence" : "doors" } }
],
"slop" : 255,
"in_order" : true,
"collect_payloads" : false
}
},
"fields": []
}'
echo
echo "hole ... nasty"
curl "localhost:9200/test-idx/doc/_search?pretty=true" -d '{
"query": {
"span_near" : {
"clauses" : [
{ "span_term" : { "sentence" : "hole" } },
{ "span_term" : { "sentence" : "nasty" } }
],
"slop" : 255,
"in_order" : true,
"collect_payloads" : false
}
},
"fields": []
}'
echo
echo "people ... green"
curl "localhost:9200/test-idx/doc/_search?pretty=true" -d '{
"query": {
"span_near" : {
"clauses" : [
{ "span_term" : { "sentence" : "people" } },
{ "span_term" : { "sentence" : "green" } }
],
"slop" : 255,
"in_order" : true,
"collect_payloads" : false
}
},
"fields": []
}'
echo
echo "sun ... orbiting"
curl "localhost:9200/test-idx/doc/_search?pretty=true" -d '{
"query": {
"span_near" : {
"clauses" : [
{ "span_term" : { "sentence" : "sun" } },
{ "span_term" : { "sentence" : "orbiting" } }
],
"slop" : 255,
"in_order" : true,
"collect_payloads" : false
}
},
"fields": []
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment