Created
March 7, 2013 03:35
-
-
Save elvuel/5105412 to your computer and use it in GitHub Desktop.
ruby hbase elasticserach with massive_record and tire
This file contains 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
# encoding: utf-8 | |
# investigation | |
require 'massive_record' | |
require 'active_model' | |
require 'json' | |
require 'tire' | |
require 'rest_client' | |
MassiveRecord::ORM::Base.connection_configuration = { | |
:host => 'localhost', | |
:port => 9090 | |
} | |
MassiveRecord::ORM::Base.table_name_suffix = "_development" | |
#### | |
## Get Settings | |
#curl -XGET 'http://localhost:9200/users/_settings' | |
#### | |
## Get Mappings | |
#curl -XGET 'http://localhost:9200/users/_mapping' | |
# curl -XDELETE 'http://localhost:9200/users/' 删除index | |
# curl -XGET 'http://localhost:9200/_status' 查看index | |
class User < MassiveRecord::ORM::Table | |
include ActiveModel::Serialization | |
include Tire::Model::Search | |
include Tire::Model::Callbacks | |
attr_accessible :email, :name, :password_salt | |
column_family :info do | |
field :name | |
field :email | |
timestamps # ..or field :created_at, :time | |
end | |
def default_id | |
"users-#{Time.now.to_f * 1000}" | |
end | |
validates_presence_of :name, :email | |
end | |
User.create(name: 'elvuel', email: '[email protected]') | |
#s = User.search('elvuel') | |
s = Tire.search 'users' do | |
query do | |
string 'name:e*' | |
end | |
end | |
s.results.each do |item| | |
p item.class | |
p item | |
end | |
puts "ok" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment