public
Last active

Test of attachments plugin

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
#!/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" ]
# }
# } ]
# }
#}

Do you have a script for Win32?
I'm not sure how to execute this part of the script on Windows.

coded=cat fn6742.pdf | perl -MMIME::Base64 -ne 'print encode_base64($_)'
In a windows command windows I can run "type fn6742.pdf | perl -MMIME::Base64 -ne 'print encode_base64($_)'`
I get the error:
Can't locate IME/Base64.pm in @INC (@INC contains: c:/Perl/site/lib c:/Perl/lib
.).
BEGIN failed--compilation aborted.
The process tried to write to a nonexistent pipe.

This helped me so much with custom attachment type support implementation for django-haystack!!!

Thank you very much Lukas!

This helped me a ton. Thanks! I made a similar gist using Python - inspired by this one. https://gist.github.com/stevehanson/7461706

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.