Last active
March 25, 2017 09:57
-
-
Save karmi/5594127 to your computer and use it in GitHub Desktop.
Example of Elasticsearch's attachment handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{\rtf1\ansi\ansicpg1250\cocoartf1038\cocoasubrtf350 | |
{\fonttbl\f0\fswiss\fcharset0 Helvetica;} | |
{\colortbl;\red255\green255\blue255;} | |
{\info | |
{\title Test RTF document} | |
{\author John Smith} | |
{\*\company My Organization}}\paperw11900\paperh16840\margl1440\margr1440\vieww9000\viewh8400\viewkind0 | |
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\ql\qnatural\pardirnatural | |
\f0\fs24 \cf0 Test RTF document.\ | |
\ | |
Lorem ipsum dolor.} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example of handling attachments in Elasticsearch | |
# ================================================ | |
# | |
# 1. Install the plugin: $ plugin -install elasticsearch/elasticsearch-mapper-attachments/1.7.0 | |
# 2. Run the script: $ bash test_attachments.sh | |
# | |
# More info: <http://www.elasticsearch.org/guide/reference/mapping/attachment-type/> | |
curl -X DELETE http://localhost:9200/test_attachments | |
echo; | |
curl -X POST http://localhost:9200/test_attachments -d '{ | |
"mappings" : { | |
"document" : { | |
"properties" : { | |
"content" : { | |
"type" : "attachment", | |
"fields" : { | |
"content" : { "store" : "yes" }, | |
"author" : { "store" : "yes" }, | |
"title" : { "store" : "yes", "analyzer" : "english"}, | |
"date" : { "store" : "yes" }, | |
"keywords" : { "store" : "yes", "analyzer" : "keyword" }, | |
"_name" : { "store" : "yes" }, | |
"_content_type" : { "store" : "yes" } | |
} | |
} | |
} | |
} | |
} | |
}' | |
echo; | |
echo '>>> Index the document' | |
curl -i -X PUT http://localhost:9200/test_attachments/document/1 -d "{ | |
\"_name\" : \"test.doc\", | |
\"content\" : \"$(openssl base64 -in test.doc)\" | |
}" | |
echo; | |
curl -X POST http://localhost:9200/test_attachments/_refresh | |
echo; echo ">>> Search for author 'John'" | |
curl "http://localhost:9200/test_attachments/_search?pretty=true&q=content.author:john&fields=content.title,content.author" |
Tamanna-Sharma, If you haven't already figured this out you need to restart elasticsearch for the plugin to be recognized.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I am new to ElasticSearch and mapper-attachment.
I am trying to index a pdf file into ES using your code but after deleting test_attachments index, its giving me following error:
{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"No handler for type [attachment] declared on field [content]"}],"type":"mapper_parsing_exception","reason":"Failed to parse mapping [document]: No handler for type [attachment] declared on field [content]","caused_by":{"type":"mapper_parsing_exception","reason":"No handler for type [attachment] declared on field [content]"}},"status":400}
Please let me know what I have missed in order to get this code worked.
Thanks in advance..