Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing value attribute in aggregation #28

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/elasticsearch/dsl/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@ def size(value=nil)
end
end; alias_method :size=, :size

def missing(value=nil)
if value
@missing = value
self
else
@missing
end
end; alias_method :missing=, :missing

# DSL method for building the `from` part of a search definition
#
# @return [self]
Expand Down
1 change: 1 addition & 0 deletions lib/elasticsearch/dsl/search/aggregations/terms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Terms

option_method :field
option_method :size
option_method :missing
option_method :shard_size
option_method :order
option_method :min_doc_count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ def size
@value.size
end

def missing
@value.missing
end

def <<(value)
@value << value
end
Expand Down
11 changes: 11 additions & 0 deletions spec/elasticsearch/dsl/search/aggregations/terms_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@
end
end

describe '#missing' do

before do
search.missing('bar')
end

it 'applies the option' do
expect(search.to_hash[:terms][:foo][:missing]).to eq('bar')
end
end

describe '#shard_size' do

before do
Expand Down