mongoid-elasticsearch
https://github.com/rs-pro/mongoid-elasticsearch
gem 'mongoid-elasticsearch'
$ bundle
class Post
include Mongoid::Document
include Mongoid::Elasticsearch
elasticsearch!
end
Post.es.search 'test text' # shortcut for Post.es.search({q: 'test text'})
result = Post.es.search body: {query: {...}, facets: {...}} etc
result.raw_response
result.results # by default returns an Enumerable with Post instances exactly
# like they were loaded from MongoDB
Post.es.index.create() # create index (done automatically on app boot)
Post
.es.index_all
Post.es.index.destroy(Post
.es.index.delete) # drop index
Post.es.index.reset # recreate index
Post.es.index.refresh # force index update (useful for specs)
Post.es.client # Elasticsearch::Client instance
response = Mongoid::Elasticsearch.search 'test'
Reindexing
All models
rake es:reindex
will reindex all indices managed by Mongoid::Elasticsearch
One model - Simple bulk
This is the preferred (fastest) method to reindex everything
Music::Video.es.index_all
One model - Simple
Communities::Thread.es.index.reset
Communities::Thread.enabled.each do |ingr|
ingr.es_update
end
自定义elasticsearch! : http://stackoverflow.com/questions/21430601/sorting-search-results-with-mongoid-elasticsearch-gem
ElasticSearch搜索: http://www.qwolf.com/?p=1387