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

BooleanFacet does not work with Elasticsearch connector #851

Open
JasonStoltz opened this issue Aug 16, 2022 · 3 comments
Open

BooleanFacet does not work with Elasticsearch connector #851

JasonStoltz opened this issue Aug 16, 2022 · 3 comments
Labels
bug Something isn't working pinned

Comments

@JasonStoltz
Copy link
Member

Describe the bug
See discussion here. https://discuss.elastic.co/t/search-ui-issues-with-elastic-search-connector-and-boolean-aggregations/312183/2

The BooleanFacet component does not work correctly with the Elasticsearch connector, because it's use of 0/1 values instead of true/false.

@JasonStoltz JasonStoltz added the bug Something isn't working label Aug 16, 2022
@botelastic
Copy link

botelastic bot commented Oct 15, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Is this issue still important to you? If so, please leave a comment and let us know. As always, thank you for your contributions.

@botelastic botelastic bot added the wontfix This will not be worked on label Oct 15, 2022
@botelastic botelastic bot closed this as completed Oct 22, 2022
@JasonStoltz JasonStoltz added pinned and removed wontfix This will not be worked on labels Oct 25, 2022
@JasonStoltz JasonStoltz reopened this Oct 25, 2022
@MarttiR
Copy link

MarttiR commented Dec 13, 2022

Here is a workaround for the APIConnector example from Search UI Next.js integration docs.

  async onSearch(requestState, queryConfig) {
    const response = await fetch("/api/search", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        requestState,
        queryConfig,
      }),
    });
    const { facets, ...rest } = await response.json();

    /**
     * Alter incoming facet data as a workaround for @elastic/search-ui issue.
     * See https://github.com/elastic/search-ui/issues/851
     */
    const alteredFacets = {
      ...facets,
      ...Object.fromEntries(
        Object.entries(facets)
          // Only process facets starting with "is".
          // Change this to suit the boolean field naming in your index!
          .filter(([facetName]) => facetName.startsWith("is"))
          .map(([facetName, facetValues]) => [
            facetName,
            facetValues?.map((facetValue) => ({
              ...facetValue,
              data:
                facetValue.data?.map((item) => {
                  // Map 0, 1 values to "false" and "true" strings.
                  if (item.value === 0) return { ...item, value: "false" };
                  if (item.value === 1) return { ...item, value: "true" };
                  return item;
                }) ?? [],
            })) ?? [],
          ])
      ),
    };

    return {
      ...rest,
      facets: alteredFacets,
    };
  }

@gaving
Copy link

gaving commented Dec 14, 2023

@MarttiR Thanks for posting this workaround, spent a while trying to get to the bottom why my boolean facets weren't working!

Hoping the workaround can be removed in a future release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pinned
Projects
None yet
Development

No branches or pull requests

3 participants