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

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

Open
wrigleyDan opened this issue Dec 4, 2024 · 0 comments
Open

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

wrigleyDan opened this issue Dec 4, 2024 · 0 comments

Comments

@wrigleyDan
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant