Make facets work correctly with elasticsearch connector.

Create a view with page based on an index
Create facets based on view
Add block to page
View page

Following error appears on the view page

Warning: Undefined array key "facet" in Drupal\elasticsearch_connector\Elasticsearch\Parameters\Builder\SearchBuilder->setFacets() (line 962 of modules/contrib/elasticsearch_connector/src/ElasticSearch/Parameters/Builder/SearchBuilder.php).

I'm using Drupal 9.3.5 and the following modules.

drupal/search_api: 1.x-dev,
drupal/facets: 2.0.x-dev,

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

danharper created an issue. See original summary.

danharper’s picture

Title: Latest version of facet api not working » Facets showing empty
danharper’s picture

Version: 8.0.x-dev » 8.x-7.x-dev
danharper’s picture

Issue summary: View changes
danharper’s picture

Just to add that I've also tried the stable versions of those modules too and I get the same error

"drupal/facets": "^2.0.1",
"drupal/search_api": "^1.23",
danharper’s picture

Issue summary: View changes
danharper’s picture

Issue summary: View changes
barig’s picture

Hi,

I have the same issue, I'm using drupal/facets: 1.8, drupal/search_api:1.23.0 and drupal/elasticsearch_connector:dev-8.0.x#ccfde219b47871b4c873f1e66d3facd581ed1582 (because I'm using PHP8.0 and older versions of elasticsearch_connector are not compatible).

Same error on logs:

Warning: Undefined array key "facet" in Drupal\elasticsearch_connector\Elasticsearch\Parameters\Builder\SearchBuilder->setFacets() (line 962 of /project/app/modules/contrib/elasticsearch_connector/src/ElasticSearch/Parameters/Builder/SearchBuilder.php)

Hope someone can fix this or I'll have to go back to Solr instead of ES :-/

Thanks !

phthlaap’s picture

Same issue, someone please help to check.

longwave’s picture

Version: 8.x-7.x-dev » 8.0.x-dev
Status: Active » Needs review
FileSize
1.72 KB

The warning and the empty facet results are two different bugs.

The warning is because $facet_options['facet'] doesn't seem to be set; this is only needed in the case of nested fields which I don't use, I've moved the code inside that code block but it might still be broken for nested fields.

The empty facet results are because the results are collected from Elasticsearch and then never passed back to Search API; this patch adds two lines to fix that.

I changed this back to 8.0.x because facets are working OK for me in 8.x-7.x; the code is very different.

szato’s picture

Status: Needs review » Reviewed & tested by the community

Patch #10 solved the issue. Thank you.

mparker17’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

@danharper, @barig, @phthlaap, @longwave, @szato, we changed how elasticsearch_connector-8.0.x-dev handles facets in #3270464: Investigate search_api_opensearch as base for elasticsearch_connector, and my manual testing showed facets working properly.

May we trouble you to try out the latest 8.0.x-dev release and see if it meets your needs? If it does not, may we trouble you to change this issue's "Status" back to "Needs work"?

(I'm cleaning up issues in the 8.0.x-dev branch as part of a big review of open issues for #3427243: Plan for 8.0.0-alpha release: thank you for your patience with me!)