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

Not able to create certain queries due to limitations #127

Open
tkrause opened this issue Nov 17, 2017 · 0 comments
Open

Not able to create certain queries due to limitations #127

tkrause opened this issue Nov 17, 2017 · 0 comments

Comments

@tkrause
Copy link

tkrause commented Nov 17, 2017

Currently, the query builder doesn't support certain queries due to the inability to create a nested SearchBuilder. I understand there is a nested type which isn't the same and is handled differently in ElasticSearch being a nested document.

The following SQL is just not possible to create with the query build but is supported by ElasticSearch.

WHERE (
     type = 'student'
     AND (
          school = 'abc' 
          OR school = 'bcd'
     )
)

Query Builder Syntax:

$users = \App\User::search()
                ->must()
                    ->match('type', 'student')
                    ->should()
                        ->match('school', 'abc')
                        ->match('school', 'bcd')
...

Expected DSL: https://pastebin.com/gUpgXzkw

Actual DSL: https://pastebin.com/ZPgfuDKw

This results in the following SQL:

WHERE (
    type = 'student'
    OR school = 'abc'
    OR school = 'bcd'
)

As you can see these are very different queries and from what I can see there is no way (especially in the docs) to create the first query.

We were able to get around this limitation using a macro. I'm adding this as an issue here if you would like to address it in the core as I'm sure other people have run into the same issue.

Macro Code: https://pastebin.com/8gtsQHHr

Query Builder Syntax With Macro

$users = \App\User::search()
                ->must()
                    ->match('type', 'student')
                ->nest(function ($q) {
                    $q->should()
                        ->match('school', 'abc')
                        ->match('school', 'bcd')
                })
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