New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

elasticated

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elasticated

  • 3.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Elasticated

Elasticsearch Wrapper, with Query & Mapping Builders

HOW TO instantiate a repository

repository = Elasticated::Repository.new # pointing to localhost
repository = Elasticated::Repository.new host: 'http://user:pass@192.168.1.2:9200' # pointing to some secured server
repository = Elasticated::Repository.new host: 'myhost', index: 'myindex', type: 'mytype' # pointing to some type of some index

HOW TO build a query

query = Query.build do
  filter do
    equal :first_name, 'Pablo'
  end
  conditions do
    between :age, 20, 25
    must_not do
      wildcard :second_name, 'Santiago*'
    end
    should do
      gt :age, 23
      lt :age, 22
    end
    minimum_should_match 1
  end
  post do
    equal :city, 'CABA'
  end
  aggregations do
    group :register_number, size: 10
  end
  from 5
  size 15
end
query.build # see the result

HOW TO execute a search

repository = Repository.new
query = Query.new
repository.execute_count query
repository.execute_search query
repository.execute_aggregations query
repository.execute_aggregated_search query
repository.delete_by query
repository.exists? query

HOW TO build a document and index it

document = Document.create do |doc|
  doc.id = 'my_unique_id'
  doc.index = 'myindex'
  doc.type = 'mytype'
  doc.source = { user: 'Pablo', some_field: 'some_value' }
end
repository = Repository.new
repository.index_document document

HOW TO build a document and (partially) update it

repository = Repository.new
repository.update_document 'my_unique_id', type: 'mytype', index: 'myindex', source: { new_field: 'New data' }

HOW TO get a document (or multiple documents) by id

repository = Repository.new
document = repository.get_document 'my_unique_id', type: 'mytype', index: 'myindex'
documents = repository.get_documents ['id1', 'id2', 'id3'], type: 'mytype', index: 'myindex'

HOW TO delete a document by id

repository = Repository.new
repository.delete_document 'my_unique_id', type: 'mytype', index: 'myindex'

HOW TO execute a bulk request

repository = Repository.new
document = Document.create id: 'my_id', type: 'my_type', index: 'my_index', source: { name: 'Pablo' }
bulk_request = repository.prepare_bulk do
  index_document d
  delete_document 'my_id', type: 'my_type', index: 'my_index'
  upsert_document 'my_id', type: 'my_type', index: 'my_index', source: { name: 'Santiago' }
  update_document 'my_id', type: 'my_type', index: 'my_index', source: { age: 24 }
  create_document d # this one will return error individually
end
response = repository.execute_bulk bulk_request

HOW TO start a resumable scroll

repository = Elasticated::Repository.new
query = Elasticated::Query.new
# prepare the 'search' object
search = repository.prepare_search query, index: 'my_index', type: 'my_type'
# fetch the first page of results
results = search.start
# get the scroll_id, and use it again later
scroll_id = search.scroll_id # also results.scroll_id is valid

HOW TO resume a scroll

repository = Elasticated::Repository.new
scroll_id = '...' # the scroll_id returned by the 'search' object
# prepare the 'search' object
search = repository.restore_search scroll_id
# fetch the next page of results
results = search.fetch
# fetch all pages until the search ends
results.append search.fetch until search.completed?

HOW TO build a mapping

mapping = Elasticated::Mapping.build do
  type :content do
    date :date
    string :user
    analyzed_string :user_alias
    nested :user_purchases do
      long :purchase_id
      string :items
    end
    object :user_info do
      string :address
    end
  end
end
mapping.to_h

HOW TO configure the gem

Elasticated.configure do |config|
  config.logger = Elasticated::Loggers::DefaultLogger.new
  config.scroll_expiration_time = '3m'
  config.scroll_page_size = 500
  config.search_page_size = 1000
  config.transport_options.request_timeout = 5*60
end

HOW TO configure some specific repository

repository = Repository.new
repository.logger = Elasticated::Loggers::DefaultLogger.new
repository.scroll_expiration_time = '3m'
repository.scroll_page_size = 500
repository.search_page_size = 1000
# transport_options cannot be setted for a single repository

FAQs

Package last updated on 10 Jul 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc