Module: ElasticSearch::Api::Index
- Included in:
- Client
- Defined in:
- lib/elasticsearch/client/index.rb
Instance Method Summary collapse
-
#count(query, options = {}) ⇒ Object
df The default field to use when no field prefix is defined within the query.
- #delete(id, options = {}) ⇒ Object
- #get(id, options = {}) ⇒ Object
- #index(document, options = {}) ⇒ Object
-
#scroll(scroll_id, options = {}) ⇒ Object
ids_only Return ids instead of hits.
-
#search(query, options = {}) ⇒ Object
df The default field to use when no field prefix is defined within the query.
Instance Method Details
#count(query, options = {}) ⇒ Object
df The default field to use when no field prefix is defined within the query. analyzer The analyzer name to be used when analyzing the query string. default_operator The default operator to be used, can be AND or OR. Defaults to OR.
84 85 86 87 88 89 90 |
# File 'lib/elasticsearch/client/index.rb', line 84 def count(query, ={}) set_default_scope!() = slice_hash(, :df, :analyzer, :default_operator) response = execute(:count, [:index], [:type], query, ) response["count"].to_i #TODO check if count is nil end |
#delete(id, options = {}) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/elasticsearch/client/index.rb', line 38 def delete(id, ={}) set_default_scope!() raise "index and type or defaults required" unless [:index] && [:type] result = execute(:delete, [:index], [:type], id, ) result["ok"] end |
#get(id, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/elasticsearch/client/index.rb', line 24 def get(id, ={}) set_default_scope!() raise "index and type or defaults required" unless [:index] && [:type] # index # type # id # fields hit = execute(:get, [:index], [:type], id, ) if hit Hit.new(hit).freeze end end |
#index(document, options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/elasticsearch/client/index.rb', line 6 def index(document, ={}) set_default_scope!() raise "index and type or defaults required" unless [:index] && [:type] # type # index # id (optional) # op_type (optional) # timeout (optional) # document (optional) result = execute(:index, [:index], [:type], [:id], document, ) if result["ok"] result["_id"] else false end end |
#scroll(scroll_id, options = {}) ⇒ Object
ids_only Return ids instead of hits
76 77 78 79 |
# File 'lib/elasticsearch/client/index.rb', line 76 def scroll(scroll_id, ={}) response = execute(:scroll, scroll_id) Hits.new(response, slice_hash(, :ids_only)).freeze end |
#search(query, options = {}) ⇒ Object
df The default field to use when no field prefix is defined within the query. analyzer The analyzer name to be used when analyzing the query string. default_operator The default operator to be used, can be AND or OR. Defaults to OR. explain For each hit, contain an explanation of how to scoring of the hits was computed. fields The selective fields of the document to return for each hit (fields must be stored), comma delimited. Defaults to the internal _source field. field Same as fields above, but each parameter contains a single field name to load. There can be several field parameters. sort Sorting to perform. Can either be in the form of fieldName, or fieldName:reverse (for reverse sorting). The fieldName can either be an actual field within the document, or the special score name to indicate sorting based on scores. There can be several sort parameters (order is important). from The starting from index of the hits to return. Defaults to 0. size The number of hits to return. Defaults to 10. search_type The type of the search operation to perform. Can be dfs_query_then_fetch, dfs_query_and_fetch, query_then_fetch, query_and_fetch. Defaults to query_then_fetch. scroll Get a scroll id to continue paging through the search results. Value is the time to keep a scroll request around, e.g. 5m ids_only Return ids instead of hits
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/elasticsearch/client/index.rb', line 57 def search(query, ={}) set_default_scope!() #TODO this doesn't work for facets, because they have a valid query key as element. need a list of valid toplevel keys in the search dsl #query = {:query => query} if query.is_a?(Hash) && !query[:query] # if there is no query element, wrap query in one = slice_hash(, :df, :analyzer, :default_operator, :explain, :fields, :field, :sort, :from, :size, :search_type, :limit, :per_page, :page, :offset, :scroll) [:size] ||= ([:per_page] || [:limit] || 10) [:from] ||= [:size] * ([:page].to_i-1) if [:page] && [:page].to_i > 1 [:from] ||= [:offset] if [:offset] [:fields] = "_id" if [:ids_only] response = execute(:search, [:index], [:type], query, ) Hits.new(response, slice_hash(, :per_page, :page, :ids_only)).freeze #ids_only returns array of ids instead of hits end |