
Security News
Follow-up and Clarification on Recent Malicious Ruby Gems Campaign
A clarification on our recent research investigating 60 malicious Ruby gems.
Elastico is a simple layer that enables you to use elasticsearch full API. The elasticsearch team created this great API which enables you to do almost anything todays search engines allow you to do.
Simple. Elastico is built in a way so your configuration and usage is as simple and straightforward as possible.
Full. Elastico is built to be transparent, non-blocking, non-opinionated layer between your code to elasticsearch API. Meaning Elastico won't force anything about how to index your active records models, neither how to search it.
There is one main reason for building it Simple and Full: Elasticsearch community is large. Its supportive, and very helpful, though most of it does not use ruby. Its most likely that you want to spend your time on feaguring out how to use elasticsearch rather than how to use the gem that works with elasticsearch. If you use Elastico, its most likely that your time will go to the former, and will be able to take advantage of the elasticsearch community.
You should give Elastico a try if you want to use elasticsearch full api.
In general, in order to be able to use elasticsearch search capabilities you should:
Install elasticsearch:
cd ~
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.90.5.tar.gz .
tar -zxvf elasticsearch-0.90.5.tar.gz /bin/
rm elasticsearch-0.90.5.tar.gz
Now run it:
/bin/elasticsearch-0.90.5/bin/elasticsearch -f
Add this line to your application's Gemfile:
gem 'elastico'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install elastico
In your model:
class Apple < ActiveRecord::Base
attr_accessible :color, :name
def self.prepare_elastico_settings_and_mappings_json
json = { "settings" =>
{
"number_of_shards" => 3
},
"mappings" =>
{
"apple" =>
{
"properties" =>
{
"name" => {"type" => "string"},
"color" => {"type" => "string"}
}
}
}
}.to_json
end
# include elastico only after you declared your settings and mappings json in the method prepare_elastico_settings_and_mappings_json
include Elastico
end
In your controller:
class ApplesController < ApplicationController
def index
if params[:query]
Apple.search_query = prepare_search_json_for params[:query]
@apples = Apple.elastico_search
else
@apples = Apple.all
end
end
private
def prepare_search_json_for query
json = { "query" =>
{
"term" => { "color" => query.to_s }
}
}.to_json
end
# now do something with your apples
end
Import your active record instances simply by:
Apple.elastico_import_all
Fork/Clone the example app that shows how to use Elastico here.
In order to get a model work with elasticsearch + Elastico you have to:
Mandatory
In your controller, Create a class method 'prepare_search_json_for' to be your standard search query for that model (defaults to nil). This is the same search query you would send if you were using the curl command.
In your model, Create a class method 'prepare_elastico_settings_and_mappings_json' to be your settings and mapping json (defaults to nil). This is the same search query you would send if you were using the curl command.
Optional
Set Apple.elastico_url= to be the ip of your elasticsearch server (defaults to "localhost:9200").
Set up Apple.elastico_index_name (optional - defaults to your class name followed by Rail.env; here it will be apples_development).
Set up Apple.elastico_type_name (optional - defaults to your class name; here it will be Apple).
Run Apple.elastico_import_all to import all your data.
Controll what fields are indexed by declaring a method called 'elastico_to_indexed_json'.
After every save Elastico will automatically save your instance in elasticsearch.
Import current database by Apple.elastico_import_all.
Search it: call Apple.elastico_search to get your results, or override it to better suit your needs.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)Please send your feedback to gneyal+elastico@gmail.com
FAQs
Unknown package
We found that elastico demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.
Research
/Security News
A malicious Go module posing as an SSH brute forcer exfiltrates stolen credentials to a Telegram bot controlled by a Russian-speaking threat actor.