Skip to content

Commit

Permalink
Merge pull request #19 from matthuhiggins/multi-percolate
Browse files Browse the repository at this point in the history
Percolate query supports multiple documents
  • Loading branch information
dcromer authored Aug 2, 2018
2 parents 0ac173a + 94389e2 commit e350ca0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/arelastic/queries/percolate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ def initialize(field, document, options = {})
def as_elastic
{
"percolate" => {
"field" => field,
"document" => document
"field" => field,
document_parameter_name => document
}.merge(options)
}
end

def document_parameter_name
document.is_a?(Array) ? "documents" : "document"
end
end
end
end
14 changes: 14 additions & 0 deletions test/arelastic/queries/percolate_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ def test_as_elastic
assert_equal expected, percolate.as_elastic
end

def test_as_elastic_with_multiple_documents
percolate = Arelastic::Queries::Percolate.new(
"query",
[{ "color" => "red" }, { "color" => "blue" }]
)
expected = {
"percolate" => {
"field" => "query",
"documents" => [{ "color" => "red" }, { "color" => "blue" }]
}
}
assert_equal expected, percolate.as_elastic
end

def test_as_elastic_with_options
percolate = Arelastic::Queries::Percolate.new("query", {"color" => "red"}, {"document_type" => "widget"})
expected = {
Expand Down

0 comments on commit e350ca0

Please sign in to comment.