Get random record using must_not

hello again
I need to get a random record excluding some values using must_not directive.
this is the query i've created using some online post.

{
    "index": "articles",
    "body":
    {
        "size": 1,
        "query":
        {
            "function_score":
            {
                "query":
                {
                    "must_not": [
                    {
                        "term":
                        {
                            "language.keyword": "en_US"
                        }
                    },
                    {
                        "term":
                        {
                            "language.keyword": "es_ES"
                        }
                    }]
                },
                "functions": [
                {
                    "random_score": {}
                }]
            }
        }
    }
}

but doesn't work.

"reason": "[must_not] query malformed, no start_object after query name",

without the

            'query' => [ 'must_not' => ... ],

work perfectly.
any idea?

What do you mean by "it does not work"?

sorry
I forgotten to add the reason code

You need to use a bool query.

i'm an idiot :zipper_mouth_face:

'query' => [ 'bool' => [ 'must_not' => $must_not ] ],

tnx @dadoonet

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.