Skip to content

Filters don't work with when "Hybrid" is used as the Algo #131

@wrigleyDan

Description

@wrigleyDan

When executing a hybrid search query in Chorus by selecting the "Hybrid" algorithm in the dropdown box and entering a query term and filtering afterwards, nothing happens in the frontend.

In the browser dev tools it becomes clear that the backend has an issue:

{
    "took": 21,
    "responses": [
        {
            "error": {
                "root_cause": [
                    {
                        "type": "illegal_argument_exception",
                        "reason": "hybrid query must be a top level query and cannot be wrapped into other queries"
                    }
                ],
                "type": "search_phase_execution_exception",
                "reason": "all shards failed",
                "phase": "query",
                "grouped": true,
                "failed_shards": [
                    {
                        "shard": 0,
                        "index": "ecommerce",
                        "node": "uFWvZB3JQl-ZlKAcyeiTlg",
                        "reason": {
                            "type": "illegal_argument_exception",
                            "reason": "hybrid query must be a top level query and cannot be wrapped into other queries"
                        }
                    }
                ],
                "caused_by": {
                    "type": "illegal_argument_exception",
                    "reason": "hybrid query must be a top level query and cannot be wrapped into other queries",
                    "caused_by": {
                        "type": "illegal_argument_exception",
                        "reason": "hybrid query must be a top level query and cannot be wrapped into other queries"
                    }
                }
            },
            "status": 400
        },
        {
            "error": {
                "root_cause": [
                    {
                        "type": "illegal_argument_exception",
                        "reason": "hybrid query must be a top level query and cannot be wrapped into other queries"
                    }
                ],
                "type": "search_phase_execution_exception",
                "reason": "all shards failed",
                "phase": "query",
                "grouped": true,
                "failed_shards": [
                    {
                        "shard": 0,
                        "index": "ecommerce",
                        "node": "uFWvZB3JQl-ZlKAcyeiTlg",
                        "reason": {
                            "type": "illegal_argument_exception",
                            "reason": "hybrid query must be a top level query and cannot be wrapped into other queries"
                        }
                    }
                ],
                "caused_by": {
                    "type": "illegal_argument_exception",
                    "reason": "hybrid query must be a top level query and cannot be wrapped into other queries",
                    "caused_by": {
                        "type": "illegal_argument_exception",
                        "reason": "hybrid query must be a top level query and cannot be wrapped into other queries"
                    }
                }
            },
            "status": 400
        }
    ]
}

Query payload - how the query looks like that Reactivesearch is building:

GET ecommerce/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "must": [
              {
                "hybrid": {
                  "queries": [
                    {
                      "match": {
                        "title_text": {
                          "query": "claypottery"
                        }
                      }
                    },
                    {
                      "neural": {
                        "title_embedding": {
                          "query_text": "claypottery",
                          "k": 50
                        }
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "should": [
                    {
                      "terms": {
                        "attrs.Brand.keyword": [
                          "Antallcky"
                        ]
                      }
                    }
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  },
  "size": 20,
  "_source": {
    "includes": [
      "*"
    ],
    "excludes": [
      "title_embedding",
      "reviews",
      "description",
      "bullets"
    ]
  },
  "search_pipeline": "hybrid-search-pipeline",
  "ext": {
    "ubi": {
      "query_id": "00f48767-3938-4ee3-b836-eeb9203c4e18",
      "user_query": "claypottery",
      "client_id": "CLIENT-eeed-43de-959d-90e6040e84f9",
      "object_id_field": "asin",
      "application": "Chorus",
      "query_attributes": {}
    }
  },
  "aggs": {
    "attrs.Brand.keyword": {
      "terms": {
        "field": "attrs.Brand.keyword",
        "size": 20,
        "order": {
          "_count": "desc"
        }
      }
    }
  },
  "from": 0
}

How the query should look like - with post filtering:

GET ecommerce/_search
{
  "query": {
    "hybrid": {
      "queries": [
        {
          "match": {
            "title_text": {
              "query": "claypottery"
            }
          }
        },
        {
          "neural": {
            "title_embedding": {
              "query_text": "claypottery",
              "k": 50
            }
          }
        }
      ]
    }
  },
  "post_filter": {
    "match": {
      "attrs.Brand.keyword": "Antallcky"
    }
  },
  "size": 20,
  "_source": {
    "includes": [
      "*"
    ],
    "excludes": [
      "title_embedding",
      "reviews",
      "description",
      "bullets"
    ]
  },
  "search_pipeline": "hybrid-search-pipeline",
  "ext": {
    "ubi": {
      "query_id": "00f48767-3938-4ee3-b836-eeb9203c4e18",
      "user_query": "claypottery",
      "client_id": "CLIENT-eeed-43de-959d-90e6040e84f9",
      "object_id_field": "asin",
      "application": "Chorus",
      "query_attributes": {}
    }
  },
  "aggs": {
    "attrs.Brand.keyword": {
      "terms": {
        "field": "attrs.Brand.keyword",
        "size": 20,
        "order": {
          "_count": "desc"
        }
      }
    }
  },
  "from": 0
}

Note: "Keyword" and "Neural" both work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions