arelastic
arelastic copied to clipboard
trouble with syntax
I'm having trouble figuring out the query for something like the following (more examples / documentation would be helpful). Can you guide me in the right direction as to how
{
"query": {
"terms": {
"type": ["some type"]
}
},
"size": 0,
"aggs": {
"documents": {
"terms": {
"field": "group_id"
}
}
}
}
I started with the query:
Arelastic::Builders::Queries.terms(
'type', ['some type'])
and then the aggregation
Arelastic::Searches::Aggregations.new(
Arelastic::Aggregations::Terms.new('documents', 'field' => 'group_id'))
# {"aggs"=>{"documents"=>{"terms"=>{"field"=>"group_id"}}}}
How do I piece them together to get the above query?
This should produce the query you are after:
Arelastic::Nodes::HashGroup.new([
Arelastic::Searches::Query.new(
Arelastic::Builders::Queries.terms('type', ['some type'])),
Arelastic::Searches::Size.new(0),
Arelastic::Searches::Aggregations.new(
Arelastic::Aggregations::Terms.new('documents', 'field' => 'group_id'))
]).as_elastic
Some additional examples have been added to the README which hopefully makes this more clear.