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



22
23
24
25
# File 'lib/elasticsearch/dsl/search/collapse.rb', line 22

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



44
45
46
47
# File 'lib/elasticsearch/dsl/search/collapse.rb', line 44

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



59
60
61
62
# File 'lib/elasticsearch/dsl/search/collapse.rb', line 59

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



74
75
76
77
78
# File 'lib/elasticsearch/dsl/search/collapse.rb', line 74

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