Method: Elasticated::QueryConditions#build

Defined in:
lib/elasticated/query_conditions.rb

#buildObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/elasticated/query_conditions.rb', line 66

def build
  if empty?
    { match_all: {} }
  elsif _must_not.empty? && _should.empty? && _must.count == 1
    _must.build_first
  elsif _must_not.empty? && _must.empty? && _should.count == 1
    _should.build_first
  else
    bool = {}
    bool.merge! must: _must.build unless _must.empty?
    bool.merge! must_not: _must_not.build unless _must_not.empty?
    if !_should.empty?
      bool.merge! should: _should.build
      bool.merge! minimum_should_match: _minimum_should_match if _minimum_should_match
    end
    bool.merge! _cache: _cache if _cache
    { bool: bool }
  end
end