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

how to perform Q booleans #102

Open
priamai opened this issue Feb 2, 2022 · 1 comment
Open

how to perform Q booleans #102

priamai opened this issue Feb 2, 2022 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@priamai
Copy link

priamai commented Feb 2, 2022

Hi there,
what should I do to include a boolean query like this:

q_and = Q('bool', must=[Q('match', act__keyword='A'), Q('match', cat__keyword='B')])

q = s<here?>.size(0).\
groupby('cat.keyword',size=100).\

response = q.execute()
data_df = response.aggregations.to_dataframe()
data_df

There is this: https://pandagg.readthedocs.io/en/v0.0.2/reference/pandagg.node.query.compound.html
but I don't know how to use it.

@leonardbinet
Copy link
Collaborator

The documentation is clearly lacking 😓

There are quite a lot of options offered to you:

Usage of .bool:

from pandagg import Search
from pandagg.query import Match

Search()\
    .bool(must=[Match(act__keyword="A"), Match(cat__keyword="B")])

# OR

Search()\
    .bool(must=[{"match": {"act.keyword": "A"}}, {"match": {"cat.keyword": "B"}}])

Using must twice:

Search()\
    .must(Match(act__keyword="A"))\
    .must(Match(cat__keyword="B"))

Search()\
    .must("match", act__keyword="A")\
    .must("match", cat__keyword="B")

Using regular dict query:

Search().query(
        {
            "bool": {
                "must": [
                    {"match": {"act.keyword": {"query": "A"}}},
                    {"match": {"cat.keyword": {"query": "B"}}},
                ]
            }
        }
)

@leonardbinet leonardbinet added the documentation Improvements or additions to documentation label Feb 17, 2022
@leonardbinet leonardbinet added this to the Solid documentation milestone Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Development

No branches or pull requests

2 participants