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

Convert multiple queries for facets with filter applied to one query (open search supports this via post_filter + a filter within aggs) #375

Open
amywieliczka opened this issue Jun 4, 2024 · 1 comment
Assignees
Labels
calisphere frontend Issues related to Calisphere's UI performance

Comments

@amywieliczka
Copy link

amywieliczka commented Jun 4, 2024

This query will return all documents with "solr" in the title as a query response.

The aggregations will aggregate on that entire query response to get all tags for all documents with "solr" in the title.

The second aggregation will filter that entire query response for documents with "solr" in the title and "elasticsearch" in the tags, and then aggregate to get all uploaders for the filtered subset of the query response.

Finally, post filter will filter all the documents with "solr" in the title to return only those documents with "solr" in the title and "elasticsearch" in tags.

This enables precisely the kind of behavior we see in our faceting sidebar, but without having to run multiple queries in order to exclude the "elasticsearch" filter from our facet request.

GET videosearch/_search:

{
  "query": {
    "bool": {
      "must": {
        "match": {
          "title": "solr"
        }
      }
    }
  },
  "size": 0,
  "aggs": {
    "popular_tags": {
      "terms": {
        "field": "tags.keyword",
        "size": 5
      }
    },
    "popular_uploaders": {
      "filter": {
        "term": {
          "tags.keyword": "elasticsearch"
        }
      },
      "aggs": {
        "uploader_tags": {
          "terms": {
            "field": "uploaded_by.keyword"
          }
        }
      }
    }
  },
  "post_filter": {
    "term": {
      "tags.keyword": "elasticsearch"
    }
  }
}
@amywieliczka
Copy link
Author

This could be considered a post-MVP enhancement, but is probably one of the first things we should try (even before analyzing Django caching), to boost query performance on Calisphere.

@amywieliczka amywieliczka added the calisphere frontend Issues related to Calisphere's UI label Jun 11, 2024
@christinklez christinklez added the size: medium 2-3 days work label Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
calisphere frontend Issues related to Calisphere's UI performance
Projects
None yet
Development

No branches or pull requests

2 participants