I am getting the error for the below code.
public function apply(\Magento\Framework\App\RequestInterface $request)
{
$filter = $request->getParam($this->_requestVar);
if (!$filter || is_array($filter) ) {
return $this;
}
$this->appliedFilter = $filter;
$filters = explode(',', $filter);
if (!$this->filterPlus) {
$this->filterPlus = true;
}
$attribute = $this->getAttributeModel();
$productCollection = $this->getLayer()->getProductCollection();
// apply filtter to collection
$productCollection->addFieldToFilter($attribute->getAttributeCode(), ["finset" => $filters]);
foreach ($filters as $option) {
$text = $this->getOptionText($option);
if ($option && strlen($text)) {
$this->getLayer()->getState()->addFilter(
$this->_createItem($text, $option)
);
}
}
return $this;
}
The error is,
main.CRITICAL: {"error":{"root_cause":[{"type":"x_content_parse_exception","reason":"[1:263] [terms_lookup] unknown field [finset]"}],"type":"x_content_parse_exception","reason":"[1:272] [bool] failed to parse field [must]","caused_by":{"type":"x_content_parse_exception","reason":"[1:263] [terms_lookup] unknown field [finset]"}},"status":400} {"exception":"[object] (Elasticsearch\Common\Exceptions\BadRequest400Exception(code: 400): {"error":{"root_cause":[{"type":"x_content_parse_exception","reason":"[1:263] [terms_lookup] unknown field [finset]"}],"type":"x_content_parse_exception","reason":"[1:272] [bool] failed to parse field [must]","caused_by":{"type":"x_content_parse_exception","reason":"[1:263] [terms_lookup] unknown field [finset]"}},"status":400} at /opt/magento/public_html/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:632)"} []
This usually happens with multi values filter. For example,
?filter_operating_sys=501,503
The Elasticsearch version is 7.13.2
and Magento version is 2.4.2