Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

constant_score query does not support query in the code

"constant score query doesn't support query" error is coming when i am trying to run the following code.

client.search({
    index: ['index1','index2'],
    body: {
        from: 0, size: 20,
        query: {
            "constant_score": {
                boost: 1.0,
                "query": {
                    query_string: {
                        query: str,
                        fields: ['field_1']
                    }
                }
            }
        }
    },
});
like image 641
A.Code.Ran Avatar asked Oct 28 '25 23:10

A.Code.Ran


1 Answers

constant_score query wraps another query. It either accepts another query or filter . Wrap query_string in filter instead of query.

Try using the below:

client.search({
    index: ['index1','index2'],
    body: {
        from: 0, size: 20,
        query: {
            "constant_score": {
                boost: 1.0,
                filter: {
                   query_string: {
                       query: str,
                       fields: ['field_1']
                   }
                }                
            }
        }
    },
});
like image 191
Nishant Avatar answered Oct 31 '25 00:10

Nishant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!