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


(Meltemi) #1

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.

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)


(David Pilato) #2

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 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.

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)


(system) #3