How to use Conditional Facets in my App-search
I read the example github elastic docs but not working any help
Target: if choose California of states Then show conditional Facet
Here is a national park example code
const config = {
alwaysSearchOnInitialLoad: true,
searchQuery: {
result_fields: {
visitors: { raw: {} },
world_heritage_site: { raw: {} },
location: { raw: {} },
acres: { raw: {} },
square_km: { raw: {} },
title: {
snippet: {
size: 100,
fallback: true
}
},
nps_link: { raw: {} },
states: { raw: {} },
date_established: { raw: {} },
image_url: { raw: {} },
description: {
snippet: {
size: 100,
fallback: true
}
}
},
disjunctiveFacets: ["states","world_heritage_site"],
facets: {
states: { type: "value" },
}
},
conditionalFacets: {
'world_heritage_site': FilterIsSelected('states', 'California')
},
autocompleteQuery: {
results: {
resultsPerPage: 5,
result_fields: {
title: {
snippet: {
size: 100,
fallback: true
}
},
nps_link: {
raw: {}
}
}
},
suggestions: {
types: {
documents: {
fields: ["title", "description"]
}
},
size: 4
}
},
apiConnector: connector
};
function FilterIsSelected(fieldName: string, value?: string) {
return ({ filters }) => {
return filters.some(
(f) => f.field === fieldName && (!value || f.values.includes(value))
);
};
}