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

Queries/nested query #70

Closed
wants to merge 3 commits into from
Closed

Queries/nested query #70

wants to merge 3 commits into from

Conversation

msanguineti
Copy link
Contributor

Hello,

I've made this quick PR for nested queries, i.e. queries over nested objects. Also updated the docs section.

Anything missing?

@danpaz
Copy link
Owner

danpaz commented Oct 25, 2016

@msanguineti Thanks for getting the ball rolling on this 👍! This approach works, however it leaves the bulk of the query building to the user. What do you think about an approach similar to how nested filters have been implemented here? This way the api might look something like:

new Bodybuilder()
        .query('nested', 'name', 'term', 'user', 'kimchy')
        .build()

@danpaz
Copy link
Owner

danpaz commented Oct 25, 2016

Related to #36.

@msanguineti
Copy link
Contributor Author

msanguineti commented Oct 25, 2016

@danpaz indeed this is a very quick PR, but with what you propose how would the API give me this:

{
    "nested" : {
        "path" : "obj1",
        "score_mode" : "avg",
        "query" : {
            "bool" : {
                "must" : [
                    {
                        "match" : {"obj1.name" : "blue"}
                    },
                    {
                        "range" : {"obj1.count" : {"gt" : 5}}
                    }
                ]
            }
        }
    }
}

What I do is to create a match query and a range filter, then I create a bool query (must) to which I pass the [match, range] object. Finally, I pass this big object into the nested query. Of course the nested query is within something else as well...

So what is needed is a generic mechanism to nest/embed/compose queries and filters. At the very first level yes, something like nested filters is necessary so that the user passes parameters and the API builds the query/filter, but then you might need to start composing things.

To rephrase it a bit, I consider the nested query not as a final or leaf query, but more of a compound query much like bool query which wraps other queries.

Maybe I am missing something here :) so please correct me if I am talking out of my backside.

@danpaz
Copy link
Owner

danpaz commented Oct 25, 2016

So what is needed is a generic mechanism to nest/embed/compose queries and filters.

I think that's exactly right. There's discussion around this idea in #65, creating a generic API for queries/filters/aggregations which can be more easily composed. I can push the local branch that I've been experimenting with later today and I would love your feedback!

@msanguineti
Copy link
Contributor Author

I've checked out your experimental branch. I will report back but first impression is good, this is the right track.

@danpaz
Copy link
Owner

danpaz commented Jan 17, 2017

The next version of bodybuilder will support nested queries, give it a try by installing the beta release:

npm install bodybuilder@beta

And see this example for its usage.

If this doesn't solve your issue please reopen!

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

Successfully merging this pull request may close these issues.

None yet

2 participants