Merging Multiple Facet Conditions in facets_post_filters with OR Conjunction in Elasticsearch Connector

Created on 7 January 2025, about 2 months ago

The current implementation of the Elasticsearch Connector module does not correctly handle multiple conditions for facets with an OR conjunction when building the facets_post_filters.

This leads to incomplete or incorrect filtering of facet results in the generated Elasticsearch query. For example, when filtering facets based on multiple content_type values, only the last condition is respected, and earlier conditions are ignored.

Steps to reproduce

Create a few content types: article and blog_post.
Create field for each with reference to taxonomy vocabulary like: field_topics.
Configure search index accordingly.
Example:
Article 1:
- topic 1
- topic 2
Article 2:
- topic 3
Blog post 1:
- topic 4
- topic 5

Configure a facets for both content_type and topics in a search view. Choose e.g., content_type = article OR blog_post
Expected result for the given case of content_type OR:
- topic 1,2,3,4,5
Actual result:
- topic 1,2,3

During inspection of the generated Elasticsearch query I find out that only the last condition is included in the facets_post_filters. And in general the interpretation of Search API query with given facets is not as expected.

The updated code addresses this issue by merging the values of multiple conditions into a single terms filter.

The updated logic ensures that:

  • If a filter for the same field already exists in facets_post_filters, the new condition values are merged with the existing ones, preserving uniqueness.
  • If no filter exists for the field, a new terms filter is created with the condition values.

expected query to elastic search is:

"facets_post_filters": {
  "content_type": {
    "<strong>terms</strong>": {
      "content_type": ["article", "blog_post"]
    }
  }
}
πŸ› Bug report
Status

Active

Version

8.0

Component

Elasticsearch Connector

Created by

πŸ‡ΊπŸ‡¦Ukraine kir.lazur@gmail.com Kiev

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024