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 get empty buckets? #114

Open
jschoedt opened this issue Apr 26, 2022 · 2 comments
Open

how to get empty buckets? #114

jschoedt opened this issue Apr 26, 2022 · 2 comments

Comments

@jschoedt
Copy link

Hi,

Is there a way to get all the buckets (also empty ones) in a result? It would be useful in "should" (or) queries to expand the search.
We can get around it doing an extra query but its a bit cumbersome.

Thanks

PS: I tried posting a similar question in the Google Group (as it seems more appropriate for questions), but it did not go through.

@mschoch
Copy link
Member

mschoch commented Apr 29, 2022

Sorry for the issue posting to the google group. Everyone's first message to the group is moderated, and I must have missed the notification that your message was in the queue. I will try to add more moderators to the group so we can avoid this in the future.

Can you provide an example of what you are asking for? Like what kind of query and facets are you specifying, and which empty buckets you want returned (some facets create buckets dynamically, making this part unclear)?

@jschoedt
Copy link
Author

jschoedt commented May 2, 2022

Ok no problem. Since you answer here - lets continue...

Yes sure. I add fields like this to the documents:

doc.AddField(bluge.NewKeywordField("color", c).Aggregatable())
...

And then when I create a search I specify the same eg.

q.SetMinShould(1)
// add filters
q.AddShould(bluge.NewTermQuery("black").SetField("color"))
...
agg := aggregations.NewTermsAggregation(search.Field("color"), 10)
req.AddAggregation("color", agg)
...

In this case I will get the "color" aggregation in the result, but it will only contain the "black" bucket with some count value > 0.
I would like to get all the colors with a count = 0 as well.

Is there an option for that?

Thanks in advance,

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

No branches or pull requests

2 participants