Skip to content

Instantly share code, notes, and snippets.

@nik9000
Last active December 22, 2015 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nik9000/6451307 to your computer and use it in GitHub Desktop.
Save nik9000/6451307 to your computer and use it in GitHub Desktop.
#!/bin/bash
curl -XDELETE http://localhost:9200/test?pretty
curl -XPUT http://localhost:9200/test?pretty
curl -XPUT http://localhost:9200/test/test/_mapping?pretty -d'{
"test" : {
"properties": {
"text" : {
"type": "string",
"store": "yes",
"term_vector" : "with_positions_offsets"
}
}
}
}'
# This is a portion of http://en.wikipedia.org/wiki/Rashidun_Caliphate which is license CC-BY-SA
cat > text <<END
...elided for brevity...
In the last week of May 633 , the capital city of Iraq fell to the Muslims after initial resistance in the Battle of Hira. File:Ctesiphon, Iraq (2117465493).jpg Remains of Taq-i Kisra,
...elided for brevity...
The Persians once again concentrated armies to regain the lost Mesopotamia, while Mithna ibn Haris withdraw from central Iraq to the region near the Arabian desert to delay war until reinforcement came from Madinah.
...elided for brevity...
END
echo -n '{"text": "' > doc
sed ':a;N;$!ba;s/\n/\\n/g' < text >> doc # Thanks http://stackoverflow.com/questions/1251999/sed-how-can-i-replace-a-newline-n
echo '"}' >> doc
curl -XPUT http://localhost:9200/test/test/1?pretty -d @doc
curl -XPOST http://localhost:9200/test/_refresh?pretty
curl -XPOST http://localhost:9200/test/test/_search?pretty -d'{
"fields": [
"_id"
],
"highlight": {
"order": "score",
"fields": {
"text": {
"number_of_fragments": 1
}
}
},
"query": {
"match": {
"text": {
"query": "central iraq",
"phrase_slop": 3
}
}
},
"rescore": {
"window_size" : 50,
"query": {
"rescore_query": {
"match_phrase": {
"text": {
"query": "central iraq",
"phrase_slop": 3
}
}
},
"query_weight": 1.0,
"rescore_query_weight": 10.0
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment