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

Query / filter/ aggregation "X" is not supported #65

Closed
danpaz opened this issue Oct 8, 2016 · 3 comments
Closed

Query / filter/ aggregation "X" is not supported #65

danpaz opened this issue Oct 8, 2016 · 3 comments

Comments

@danpaz
Copy link
Owner

danpaz commented Oct 8, 2016

Right now bodybuilder depends on having a definition for every filter/query/aggregation in the elasticsearch query dsl (which is a lot). This works, and gives a high degree of control over how to construct each filter/query/aggregation clause. However,

Proposals

Some ideas I had to improve this:

  • Allow custom filter/query/aggregation clauses. Maybe it could look something like:
new Bodybuilder().filter('custom', { ... })
or
new Bodybuilder().rawFilter({ ... })

This way bodybuilder can continue to be useful while users wait for a PR to add their definition is merged.

  • Generalize the filter/aggregation/query builders such that maybe we don't need definitions for individual clauses at all. Most clauses follow a predictable structure. Example:
.filter(<type>, <field>, <value>)
becomes
{
  <type> {
    <field>: <value>
  }
}

// Example
.filter('term', 'user', 'kimchy')
becomes
{
  term: {
    user: 'kimchy'
  }
}

Still thinking these ideas through and looking for feedback from anyone on this!

@johannes-scharlach
Copy link
Collaborator

johannes-scharlach commented Oct 10, 2016

Big 👍 for custom aggregations. The syntax there is less predictable and prior to creating #64, that was the feature I was looking for.

With filters & queries: My feeling is that the syntax there is very predictable, so I'd generally expect a .filter(<type>, <field>, <value>) API. The <type> can even be generically converted from camelCase and kebab-case to snake_case. (lodash has some convenience functions around that)

@danpaz
Copy link
Owner Author

danpaz commented Oct 25, 2016

Starting to look at what it would take to put together a generic api for queries/filters, I started collecting notes trying to categorize all the different forms a query clause can take.

Query/Filter structures I've observed:

No field (Match All query):

{
  <type>: {}
}
// example:
{
  match_all: {}
}

Field but no value:

{
  <type>: {
    field: <field>
  }
}
// or
{
  <type>: {
    value: <field>
  }
}
// examples:
{
  exists: {
    field: 'some_field_name'
  }
}
{
  type: {
    value: 'some_type_name'
  }
}

Field with value:

{
  <type>: {
    <field>: <value>
  }
}
// examples:
{
  term: {
    user: 'kimchy'
  }
}
{
  terms: {
    user: ['kimchy', 'rob']
  }
}

Field with value and more options:

{
  <type>: {
    <field>: <value>,
    <a>: <b>,
    <c>: <d>,
    ...
  }
}
// example:
{
  geo_distance: {
    distance: '12km',
    point: {
      lat: 40,
      lon: 20
    }
  }
}

Join queries such as nested query:

{
  <type>: {
    path: <parent_field>,
    query: {
      <type>: {
        '<parent_field>.<child_field>': <value>
      }
    }
  }
}
// examples:
{
  nested: {
    path: 'obj1',
    query: {
      match: {
        'obj1.color': 'blue'
      }
    }
  }
}
{
  has_child: {
    type: 'blog_tag',
    query: {
      term: {
        tag: 'something'
      }
    }
  }
}
// perhaps these can be treated as a special case of nested queries?

@danpaz
Copy link
Owner Author

danpaz commented Jan 17, 2017

@danpaz danpaz closed this as completed Jan 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants