Using elasticsearch terminate after in query body in javascript

I am trying to get only one result back for a query I know may return more than one result, so I would like to use the the terminate_after parameter, but I can’t work out how to use it in a query body in javascript. I have tried putting it in the body, like below, but I get a parsing_exception: “Unknown key for a VALUE_NUMBER in [terminateAfter].”

client.search({
    index: 'myindex',
    type: 'mytype',
    body: {
        terminateAfter: 1,
        query: {
            term: {
                searchField: searchString
            }
        }
    }
}, function(error, results){}

I have also tried putting it inside the query, but this also causes a parsing_exception: “[terminateAfter] query malformed, no start_object after query name”

I am using version 5.3 of elasticsearch and version 13.3.1 of the elasticsearch npm module.

You’ve almost got it right, terminateAfter should go outside the body, like this:

client.search({
    index: 'myindex',
    type: 'mytype',
    terminateAfter: 1,
    body: {
        query: {
            term: {
                searchField: searchString
            }
        }
    }
}, function(error, results){}