我仍然使用Tire gem来使用0.9 ES数据库。
我有一个看起来像这样的模型:
class Influencer
include Tire::Model::Persistence
include Tire::Model::DynamicPersistence
document_type "influencer"
# profiles
property :profiles, :type => 'nested', :class => [Profile], :default => []
end
我还有一个看起来像这样的Profile类。
class Profile
include Tire::Model::Persistence
include Tire::Model::DynamicPersistence
document_type 'profile'
property :id, :index => :not_analyzed
property :username, :index => :not_analyzed
property :service, :index => 'keyword'
property :url, :index => :not_analyzed
property :score, :type => 'float', :index => :not_analyzed
end
注意我删除了很多字段。
所以,当我吹走索引并为影响者重新创建它时,我得到一个空索引。在第一次写入时,它会在下面创建映射:
{"influencer"=>
{"properties"=>
{"data"=>{"type"=>"object"},
"demographics"=>{"type"=>"object"},
"domain_names"=>{"type"=>"string"},
"geographics"=>{"type"=>"object"},
"host_names"=>{"type"=>"string"},
"id"=>{"type"=>"string"},
"income_message_numbers"=>{"type"=>"object"},
"influencer_id"=>{"type"=>"string"},
"keyword_scores"=>{"type"=>"object"},
"keywords"=>{"type"=>"string"},
"manual"=>{"type"=>"boolean"},
"name"=>{"type"=>"string"},
"notes"=>{"type"=>"object"},
"profiles"=>
{"properties"=>
{"profile"=>
{"properties"=>
{"contributors_enabled"=>{"type"=>"boolean"},
"default_profile"=>{"type"=>"boolean"},
"description"=>{"type"=>"string"},
"favourites_count"=>{"type"=>"long"},
"followers_count"=>{"type"=>"long"},
"friends_count"=>{"type"=>"long"},
"id"=>{"type"=>"long"},
"lang"=>{"type"=>"string"},
"listed_count"=>{"type"=>"long"},
"location"=>{"type"=>"string"},
"name"=>{"type"=>"string"},
"profile_image_url"=>{"type"=>"string"},
"protected"=>{"type"=>"boolean"},
"service"=>{"type"=>"string"},
"statuses_count"=>{"type"=>"long"},
"url"=>{"type"=>"string"},
"username"=>{"type"=>"string"}}}}},
"project_profiles"=>{"type"=>"object"},
"project_statuses"=>{"type"=>"object"},
"project_tags"=>{"type"=>"object"},
"project_time_additions"=>{"type"=>"object"},
"reachable_via"=>{"type"=>"string"},
"share_counts"=>{"type"=>"object"},
"source_ids"=>{"type"=>"string"},
"sources"=>{"type"=>"string"}}}}
这是写入的第一个哈希看起来像。我认为它看起来是正确的,但我很可能会遗漏一些东西。
{:name=>"DogeWire", :profiles=>[{"service"=>"twitter", "id"=>2465530645, "name"=>"DogeWire", "username"=>"DogeWire", "description"=>"Fast, safe, anonymous, wow", "location"=>"www.DogeWire.com", "protected"=>false, "followers_count"=>466, "friends_count"=>1990, "listed_count"=>2, "favourites_count"=>19, "statuses_count"=>8421, "lang"=>"en", "contributors_enabled"=>false, "profile_image_url"=>"http://pbs.twimg.com/profile_images/460517818555846656/-0Ibxod4_normal.jpeg", "url"=>"http://twitter.com/DogeWire", "default_profile"=>true, "time_zone"=>nil}], :source_ids=>["twitter:2465530645"], :sources=>["twitter"], :keywords=>["altcoin"], :reachable_via=>["twitter"], :tags=>[], :host_names=>["www.lill.com"], :domain_names=>["lill.com"], :id=>"74uF9cNfW6dYEa27kSg5ww", :influencer_id=>"74uF9cNfW6dYEa27kSg5ww"}
最后,查询如下:
site_influencers = Influencer.search(:page => 1, :per_page => 10) do
query do
nested :path => 'profiles' do
query do
boolean do
must { match 'profiles.service', 'twitter' }
end
end
end
end
end
我不确定我错过了什么。这是一个ruby app ..没有Rails(但有ActiveRecord等)。
有什么想法?