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

trouble with syntax #25

Open
schowdhury opened this issue Sep 23, 2019 · 1 comment
Open

trouble with syntax #25

schowdhury opened this issue Sep 23, 2019 · 1 comment
Labels

Comments

@schowdhury
Copy link

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?

@j1wilmot
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants