Skip to content

Instantly share code, notes, and snippets.

Created May 21, 2014 04:52
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 anonymous/0e75d85d3a8e97c95f63 to your computer and use it in GitHub Desktop.
Save anonymous/0e75d85d3a8e97c95f63 to your computer and use it in GitHub Desktop.
Mapper Attachment Elasticsearch
#!/bin/sh
host=http://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 PUT "${host}/test/stories/_mapping" -d '{
"stories" : {
"properties" : {
"story_name" : {"type" : "string"},
"files":{
"type":"nested",
"path":"full",
"include_in_root":"true",
"properties" : {
"file" : {
"type" : "attachment",
"fields" : {
"title" : { "store" : "yes" },
"file" : { "term_vector":"with_positions_offsets", "store":"yes" }
}
}
}
}
}
}
}'
curl -X POST "${host}/test/stories/" -d '{"story_name":"Story 2", "files" :[{"file" : "d29ybGQgaXMgYmVhdXRpZnVs"},{"file":"d29ybGQ="}]}'
echo
curl -XPOST "${host}/_refresh"
curl "${host}/test/stories/_search?pretty=true" -d '{
"fields" : ["story_name", "files.file"],
"query" : {
"query_string" : {
"query" : "world"
}
},
"highlight" : {
"fields" : {
"files.file" : {}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment