Class: Elasticsearch::DSL::Search::Collapse

Inherits:
Object
  • Object
show all
Includes:
BaseComponent
Defined in:
lib/elasticsearch/dsl/search/collapse.rb

Overview

Wraps the ‘collapse` part of a search definition

Instance Method Summary collapse

Methods included from BaseComponent

included

Constructor Details

#initialize(field, &block) ⇒ Collapse

Initialize the field collapse definition.

Parameters:

  • field (String, Symbol)

    The name of the field.

Since:

  • 0.1.9



35
36
37
38
# File 'lib/elasticsearch/dsl/search/collapse.rb', line 35

def initialize(field, &block)
  @hash = { field: field }
  @block = block
end

Instance Method Details

#inner_hits(name, &block) ⇒ Object

Create an inner_hits definition.

Examples:

collapse :user
  inner_hits 'last_tweet' do
    size 10
    from 5
    sort do
      by :date, order: 'desc'
      by :likes, order: 'asc'
    end
  end
end

Returns:

  • self

Since:

  • 0.1.9



57
58
59
60
# File 'lib/elasticsearch/dsl/search/collapse.rb', line 57

def inner_hits(name, &block)
  @inner_hits = Queries::InnerHits.new(name, &block)
  self
end

#max_concurrent_group_searches(max) ⇒ Object

Specify the max_concurrent_group_searches setting on the collapse definition.

Examples:

collapse :user
  max_concurrent_group_searches 4
end

Returns:

  • self.

Since:

  • 0.1.9



72
73
74
75
# File 'lib/elasticsearch/dsl/search/collapse.rb', line 72

def max_concurrent_group_searches(max)
  @hash[:max_concurrent_group_searches] = max
  self
end

#to_hashHash

Convert the definition to a hash, to be used in a search request.

Examples:

definition = collapse :user
  max_concurrent_group_searches 4
end

Returns:

  • (Hash)

    The collapse clause as a hash.

Since:

  • 0.1.9



87
88
89
90
91
# File 'lib/elasticsearch/dsl/search/collapse.rb', line 87

def to_hash
  call
  @hash[:inner_hits] = @inner_hits.to_hash if @inner_hits
  @hash
end