Java Elasticsearch:附件类型为空时的索引对象
我正在尝试使用Elasticsearch&Tire gem为一堆文档编制索引。索引工作非常有效,除了少数情况下记录不完整,并且没有引用的Java Elasticsearch:附件类型为空时的索引对象,java,ruby-on-rails,null,elasticsearch,tire,Java,Ruby On Rails,Null,elasticsearch,Tire,我正在尝试使用Elasticsearch&Tire gem为一堆文档编制索引。索引工作非常有效,除了少数情况下记录不完整,并且没有引用的文件名。在这些情况下,记录中没有任何内容被索引,Elasticsearch抛出一个NullPointerException 我不懂Java,但想知道是否有一种方法可以将某些内容传递给附件类型插件,这样Elasticsearch就可以成功地索引记录的其余部分,而只需绕过:Type=>“Attachment”,其中Attachment返回null 尝试了“附件”:{
文件名
。在这些情况下,记录中没有任何内容被索引,Elasticsearch抛出一个NullPointerException
我不懂Java,但想知道是否有一种方法可以将某些内容传递给附件类型插件,这样Elasticsearch就可以成功地索引记录的其余部分,而只需绕过:Type=>“Attachment”
,其中Attachment
返回null
尝试了“附件”:{“类型”:“附件”,“空值”:“缺少文件”}
(或者用轮胎的说法:索引:附件,:type=>“附件”,“空值=>“缺少文件”
),但这似乎没有任何区别
#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', :null_value => 'missing_file' # <== no worky
end
def to_indexed_json
to_json(:methods => [:attachment])
end
def attachment
if filename.present?
path_to_pdf = "/Volumes/HardDisk/sample_pdfs/#{filename}.pdf"
Base64.encode64(open(path_to_pdf) { |pdf| pdf.read })
end
end
end
#Elasticsearch log:
[2012-06-29 09:01:15,515][DEBUG][action.bulk ] [Skunge the Laxidazian Troll] [articles][4] failed to execute bulk item (index) index {[articles][article][10], source[{"content":"this title is fluff","created_at":"2012-06-27T22:02:43Z","filename":null,"id":10,"published_on":"2012-06-27","title":"Test title","updated_at":"2012-06-27T22:02:43Z","attachment":null}]}
java.lang.NullPointerException
#app/models/article.rb
类文章'integer'
索引:标题
索引:内容
索引:发布时间::type=>date'
索引:附件,:type=>'attachment',:null_值=>'missing_file'.[:attachment])
结束
def附件
如果filename.present存在?
path_to_pdf=“/Volumes/HardDisk/sample_pdfs/#{filename}.pdf”
Base64.encode64(open(path_to_pdf){| pdf | pdf.read})
结束
结束
结束
#弹性搜索日志:
[2012-06-29 09:01:15515][DEBUG][action.bulk][Skunge the Laxidazian Troll][articles][4]未能执行批量项目(索引)索引{[articles][article][10],来源[{“content”:“此标题为fluff”,“已创建于”:“2012-06-27T22:02:43Z”,“文件名”:null,“id”:10,“发布于”:“2012-06-27”,“标题”:“测试标题”,“更新于”:“2012-06-27T22:02:43Z”,“附件”:null}]}”
java.lang.NullPointerException