Skip to content

Instantly share code, notes, and snippets.

@elvuel
Created March 7, 2013 03:35
Show Gist options
  • Save elvuel/5105412 to your computer and use it in GitHub Desktop.
Save elvuel/5105412 to your computer and use it in GitHub Desktop.
ruby hbase elasticserach with massive_record and tire
# 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