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

After setting distinct_attribute values inside facetStats and facetDistribution become incorrect. #4677

Closed
zxcq544 opened this issue Jun 4, 2024 · 4 comments
Labels
support Issues related to support questions

Comments

@zxcq544
Copy link

zxcq544 commented Jun 4, 2024

Describe the bug
I am building e-commerce form. To build form I use values from facetStats and facetDistribution.
Before setting distinct_attribute eveything works correctly and I get all values for price(min and max):

{'estimatedTotalHits': 2,
 'facetDistribution': {'price': {'100': 1, '200': 1}},
 'facetStats': {'price': {'max': 200.0, 'min': 100.0}}, #important
 'hits': [{'distinct_id': 1, 'id': 0, 'price': 100},
          {'distinct_id': 1, 'id': 1, 'price': 200}],
 'limit': 20,
 'offset': 0,
 'processingTimeMs': 0,
 'query': ''}

After setting distinct_attribute my facets lose data:

{'estimatedTotalHits': 1,
 'facetDistribution': {'price': {'100': 1}},
 'facetStats': {'price': {'max': 100.0, 'min': 100.0}},  #important
 'hits': [{'distinct_id': 1, 'id': 0, 'price': 100}],
 'limit': 20,
 'offset': 0,
 'processingTimeMs': 0,
 'query': ''}

Here we can see that both min and max are same and facetDistribution shrinked to 1 value.
To Reproduce
Steps to reproduce the behavior:

  1. Data that I used:
[
    {
        "id": 0,
        "price": 100,
        "distinct_id": 1
    },
    {
        "id": 1,
        "price": 200,
        "distinct_id": 1
    }
]
  1. Settings that I used(in python):
client.index(index_name).update_filterable_attributes(["price"])
client.index(index_name).update_sortable_attributes(["price", ])
client.index(index_name).update_distinct_attribute("distinct_id")

Expected behavior
I expect facets to show data for all items in index even if they are using distinct_attribute. It allows to build complete user interface forms for faceted search.

Screenshots
Because of this problem my form looks like that :
image

But it should look like that:
image

Here we can see that audio speakers are grouped by nominal impedance which is distinct_attribute for them.
But because of current facet behaviour it makes impossible to build UI forms when using facets with distinct_attribute because it shrinks data to 1 item which is shown and doesn't take in consideration all of available items.

Meilisearch version:
Package version: "1.8.0"

@zxcq544
Copy link
Author

zxcq544 commented Jun 6, 2024

Currently solved it by adding copy of index without distinct attribute. And that index is for facets only.

@ManyTheFish
Copy link
Member

Hello @zxcq544,
If I understand well, your issue seems related to the following discussion:
https://github.com/orgs/meilisearch/discussions/741

We plan to solve the issue reported in the discussion by allowing the user to set the distinctAttribute at search time instead of at setting time. This would allow you to have a consistent facetDistribution using a multi-index search.

We plan to release it in 1.9.0 but it could be delayed to 1.10.0 if we encounter any issue during the implementation. 😄

@curquiza curquiza added the support Issues related to support questions label Jun 6, 2024
@zxcq544
Copy link
Author

zxcq544 commented Jun 6, 2024

Yes I have same issue. Should I close this one ?

@curquiza
Copy link
Member

curquiza commented Jun 6, 2024

Yes, I will close it, thank you @zxcq544

@curquiza curquiza closed this as completed Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Issues related to support questions
Projects
None yet
Development

No branches or pull requests

3 participants