Giter Site home page Giter Site logo

Comments (3)

johannes-scharlach avatar johannes-scharlach commented on May 27, 2024 1

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)

from bodybuilder.

danpaz avatar danpaz commented on May 27, 2024

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?

from bodybuilder.

danpaz avatar danpaz commented on May 27, 2024

bodybuilder 2 is in beta! https://github.com/danpaz/bodybuilder/releases/tag/v2.0.0-beta.1

from bodybuilder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.