# How do you set up mapping for attachments in Elasticsearch with Tire?

**URL:** <https://discuss.elastic.co/t/how-do-you-set-up-mapping-for-attachments-in-elasticsearch-with-tire/8258>\
**Category:** Elasticsearch\
**Created:** [June 29, 2012, 5:48am UTC](https://discuss.elastic.co/t/how-do-you-set-up-mapping-for-attachments-in-elasticsearch-with-tire/8258 "2012-06-29T05:48:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Meltemi](https://avatars.discourse-cdn.com/v4/letter/m/a87d85/32.png) [@Meltemi](https://discuss.elastic.co/u/Meltemi)\
**Post date:** [June 29, 2012, 5:48am UTC](https://discuss.elastic.co/t/how-do-you-set-up-mapping-for-attachments-in-elasticsearch-with-tire/8258/1 "2012-06-29T05:48:16Z")

</div>

Having difficulty indexing an attachment type in _elasticsearch_ via the \*  
Tire\* gem. Not able to set attachment type correctly. I'm sure it's a  
syntax error or some other misunderstanding on my part.

Attachments plugin is installed as per  
[https://github.com/elasticsearch/elasticsearch-mapper-attachments](https://github.com/elasticsearch/elasticsearch-mapper-attachments).

Hoping someone can set me straight!

_#app/models/article.rb_  
class Article \< ActiveRecord::Base  
include Tire::Model::Search  
include Tire::Model::Callbacks

attr\_accessible :title, :content, :published\_on, :filename

mapping do  
indexes :id, :type =\>'integer'  
indexes :title  
indexes :content  
indexes :published\_on, :type =\> 'date'  
indexes :attachment, :type =\> 'attachment'  
end

def to\_indexed\_json  
to\_json(:methods =\> [:attachment])  
end

def attachment  
if filename.present?  
path\_to\_pdf =  
"/Volumes/Disk41402/test\_proj/sample\_pdfs/#{filename}.pdf"  
Base64.encode64(open(path\_to\_pdf) { |pdf| pdf.read })  
end  
end  
end

Log shows a No handler for type [attachment] declared on field [attachment] error  
when I try to re-index with $ rake environment tire:import CLASS=Article  
FORCE=true

Log output:

[2012-06-28 22:33:18,269][DEBUG][indices] [Solarr]  
deleting Index [articles]  
[2012-06-28 22:33:18,270][DEBUG][index.cache.filter.weighted] [Solarr]  
[articles] full cache clear, reason [close]  
[2012-06-28 22:33:18,270][DEBUG][index.cache.field.data.resident] [Solarr]  
[articles] full cache clear, reason [close]  
[2012-06-28 22:33:18,271][WARN][cluster.metadata] [Solarr]  
[articles] _failed to create_  
org.elasticsearch.index.mapper.MapperParsingException: mapping [article]  
at  
org.elasticsearch.cluster.metadata.MetaDataCreateIndexService$1.execute(MetaDataCreateIndexService.java:263)  
at  
org.elasticsearch.cluster.service.InternalClusterService$2.run(InternalClusterService.java:211)  
at  
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
at  
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
at java.lang.Thread.run(Thread.java:680)  
Caused by: org.elasticsearch.index.mapper.MapperParsingException: _No  
handler for type [attachment] declared on field [attachment]_  
at  
org.elasticsearch.index.mapper.object.ObjectMapper$TypeParser.parseProperties(ObjectMapper.java:259)  
at  
org.elasticsearch.index.mapper.object.ObjectMapper$TypeParser.parse(ObjectMapper.java:217)  
at  
org.elasticsearch.index.mapper.DocumentMapperParser.parse(DocumentMapperParser.java:161)  
at  
org.elasticsearch.index.mapper.MapperService.parse(MapperService.java:271)  
at org.elasticsearch.index.mapper.MapperService.add(MapperService.java:174)  
at  
org.elasticsearch.cluster.metadata.MetaDataCreateIndexService$1.execute(MetaDataCreateIndexService.java:260)

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 29, 2012, 6:49am UTC](https://discuss.elastic.co/t/how-do-you-set-up-mapping-for-attachments-in-elasticsearch-with-tire/8258/2 "2012-06-29T06:49:40Z")

</div>

Your plugin is not well setup.  
When you start ES, you should see the attachment plugin in the plugin list loaded by ES.

So, have a look again at the README file in the plugin Git repo.

You need to restart ES.

David

Le 29 juin 2012 à 07:48, Meltemi [mdemetrios@gmail.com](mailto:mdemetrios@gmail.com) a écrit :

> Having difficulty indexing an attachment type in elasticsearch via the Tire gem. Not able to set attachment type correctly. I'm sure it's a syntax error or some other misunderstanding on my part.
> 
> Attachments plugin is installed as per [https://github.com/elasticsearch/elasticsearch-mapper-attachments](https://github.com/elasticsearch/elasticsearch-mapper-attachments).
> 
> Hoping someone can set me straight!
> 
> #app/models/article.rb  
> class Article \< ActiveRecord::Base  
> include Tire::Model::Search  
> include Tire::Model::Callbacks
> 
> attr\_accessible :title, :content, :published\_on, :filename
> 
> mapping do  
> indexes :id, :type =\>'integer'  
> indexes :title  
> indexes :content  
> indexes :published\_on, :type =\> 'date'  
> indexes :attachment, :type =\> 'attachment'  
> end
> 
> def to\_indexed\_json  
> to\_json(:methods =\> [:attachment])  
> end
> 
> def attachment  
> if filename.present?  
> path\_to\_pdf = "/Volumes/Disk41402/test\_proj/sample\_pdfs/#{filename}.pdf"  
> Base64.encode64(open(path\_to\_pdf) { |pdf| pdf.read })  
> end  
> end  
> end
> 
> Log shows a No handler for type [attachment] declared on field [attachment] error when I try to re-index with $ rake environment tire:import CLASS=Article FORCE=true
> 
> Log output:
> 
> [2012-06-28 22:33:18,269][DEBUG][indices] [Solarr] deleting Index [articles]  
> [2012-06-28 22:33:18,270][DEBUG][index.cache.filter.weighted] [Solarr] [articles] full cache clear, reason [close]  
> [2012-06-28 22:33:18,270][DEBUG][index.cache.field.data.resident] [Solarr] [articles] full cache clear, reason [close]  
> [2012-06-28 22:33:18,271][WARN][cluster.metadata] [Solarr] [articles] failed to create  
> org.elasticsearch.index.mapper.MapperParsingException: mapping [article]  
> at org.elasticsearch.cluster.metadata.MetaDataCreateIndexService$1.execute(MetaDataCreateIndexService.java:263)  
> at org.elasticsearch.cluster.service.InternalClusterService$2.run(InternalClusterService.java:211)  
> at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
> at java.lang.Thread.run(Thread.java:680)  
> Caused by: org.elasticsearch.index.mapper.MapperParsingException: No handler for type [attachment] declared on field [attachment]  
> at org.elasticsearch.index.mapper.object.ObjectMapper$TypeParser.parseProperties(ObjectMapper.java:259)  
> at org.elasticsearch.index.mapper.object.ObjectMapper$TypeParser.parse(ObjectMapper.java:217)  
> at org.elasticsearch.index.mapper.DocumentMapperParser.parse(DocumentMapperParser.java:161)  
> at org.elasticsearch.index.mapper.MapperService.parse(MapperService.java:271)  
> at org.elasticsearch.index.mapper.MapperService.add(MapperService.java:174)  
> at org.elasticsearch.cluster.metadata.MetaDataCreateIndexService$1.execute(MetaDataCreateIndexService.java:260)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:22am UTC](https://discuss.elastic.co/t/how-do-you-set-up-mapping-for-attachments-in-elasticsearch-with-tire/8258/3 "2017-07-06T03:22:05Z")

</div>


