Class: Elasticity::Search::ScanCursor

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/elasticity/search.rb

Instance Method Summary collapse

Constructor Details

#initialize(client, search_definition, mapper, size: 100, scroll: "1m") ⇒ ScanCursor

Returns a new instance of ScanCursor.



133
134
135
136
137
138
139
# File 'lib/elasticity/search.rb', line 133

def initialize(client, search_definition, mapper, size: 100, scroll: "1m")
  @client            = client
  @search_definition = search_definition
  @mapper            = mapper
  @size              = size
  @scroll            = scroll
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/elasticity/search.rb', line 145

def blank?
  empty?
end

#eachObject



164
165
166
167
168
# File 'lib/elasticity/search.rb', line 164

def each
  enumerator.each do |group|
    group.each { |doc| yield(doc) }
  end
end

#each_batchObject



158
159
160
161
162
# File 'lib/elasticity/search.rb', line 158

def each_batch
  enumerator.each do |group|
    yield(group)
  end
end

#empty?Boolean

Returns:

  • (Boolean)


141
142
143
# File 'lib/elasticity/search.rb', line 141

def empty?
  total == 0
end

#totalObject



149
150
151
152
153
154
155
156
# File 'lib/elasticity/search.rb', line 149

def total
  res = search["hits"]["total"]
  if res.is_a?(::Hash)
    res["value"]
  else
    res
  end
end