ElasticSearch: Combining bool and script_score in a single query

Viewed 85

I have an existing elastic bool query. I've added a dense vector field to the index and would like to search it all in one query. The compound query part of the Elastic docs seems to imply you can do this, but I can't make it work (I get a runtime error) and haven't been able to find any examples. Here's a simplified version of what I'm trying.

localQuery = {
            'bool': 
                'should': [
                    {
                        "match_phrase": {
                            "field1": {
                                "query": query,
                                "boost": 10
                            }
                        }
                    },
                    {
                        "match_phrase": {
                            "field2": {
                                "query": query,
                                "boost": 6
                            }
                        }
                    },
                    {
                         "script_score": {
                           "query": {
                              "match_all": {}
                            },
                         "script": {
                            "source": "cosineSimilarity(params.element_desc_vector, 
                                                       'description_vec') + 1.0",
                            "params": {"element_desc_vector": queryList}
                         }
                      }
                   }
               ]
             }

I'd appreciate any suggestions, pointers to examples or even a flat "no you can't do that".

Thanks Howard

0 Answers
Related