Skip to content

Instantly share code, notes, and snippets.

@michiel
Forked from lukas-vlcek/gist:1075067
Created July 2, 2014 11:41
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 michiel/013b5c54469e4707ea4f to your computer and use it in GitHub Desktop.
Save michiel/013b5c54469e4707ea4f to your computer and use it in GitHub Desktop.
#!/bin/sh
host=localhost:9200
curl -X DELETE "${host}/test"
curl -X PUT "${host}/test" -d '{
"settings" : { "index" : { "number_of_shards" : 1, "number_of_replicas" : 0 }}
}'
curl -X GET "${host}/_cluster/health?wait_for_status=green&pretty=1&timeout=5s"
curl -X PUT "${host}/test/attachment/_mapping" -d '{
"attachment" : {
"properties" : {
"file" : {
"type" : "attachment",
"fields" : {
"title" : { "store" : "yes" },
"file" : { "term_vector":"with_positions_offsets", "store":"yes" }
}
}
}
}
}'
curl -C - -O http://www.intersil.com/data/fn/fn6742.pdf
coded=`cat fn6742.pdf | perl -MMIME::Base64 -ne 'print encode_base64($_)'`
json="{\"file\":\"${coded}\"}"
echo "$json" > json.file
curl -X POST "${host}/test/attachment/" -d @json.file
echo
curl -XPOST "${host}/_refresh"
curl "${host}/_search?pretty=true" -d '{
"fields" : ["title"],
"query" : {
"query_string" : {
"query" : "amplifier"
}
},
"highlight" : {
"fields" : {
"file" : {}
}
}
}'
#
# The following is output of the last search query:
#
#
#
#{
# "took" : 6,
# "timed_out" : false,
# "_shards" : {
# "total" : 1,
# "successful" : 1,
# "failed" : 0
# },
# "hits" : {
# "total" : 1,
# "max_score" : 0.005872132,
# "hits" : [ {
# "_index" : "test",
# "_type" : "attachment",
# "_id" : "UUaHJ6CfTOC3T2I4Kj_pXg",
# "_score" : 0.005872132,
# "fields" : {
# "file.title" : "ISL99201"
# },
# "highlight" : {
# "file" : [ "\nMono <em>Amplifier</em> • Filterless Class D with Efficiency > 86% at 400mW\nThe ISL99201 is a fully integrat", "\nmono <em>amplifier</em>. It is designed to maximize performance for \nmobile phone applications. The applicat" ]
# }
# } ]
# }
#}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment