How to create this Elasticsearch query body using elastic-builder?

Viewed 138

I'd like to create this exact JSON object using elastic-builder library

   {
        track_total_hits: true,
        query: {
            script_score: {
                query: {
                    bool: {
                        must: {
                            match_all: {}
                        }
                    }
                }, script: {
                    source: "...my script..."
                }
            }
        }
    }

So that means script_score inside a query, then query again etc and if possible also how to add that track_total_hits key... I could not find a way to do that using their API.

There is a way using functionScoreQuery() to create a similar looking object, but it was not accepted. It was like below:

esb.functionScoreQuery()
        .query(esb.matchAllQuery())
        .function(esb.scriptScoreFunction(
        esb.script('source', "...my script...")
    ))

Thanks in advance!

0 Answers
Related