Can not remove hits.hits.sort field from response of /_search request with sort

Hello Elasticsearch Team,

In our use case, we want to get only document IDs of the matched documents as a result of search API /_search.

But when I call search API with a query including "sort" field, the response contains unnecessary hits.hits.sort field as follows.

  "took": 6,
  "timed_out": false,
  "_shards": {
    "total": 6,
    "successful": 6,
    "skipped": 0,
    "failed": 0
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    "max_score": null,
    "hits": [
        "_index": "example1",
        "_type": "_doc",
        "_id": "12345",
        "_score": null,
        "sort": [
          "Unnecessary keyword value",

"_source":false was ignored for the hits.hits.sort field.
In our use case, the keyword field for sort may contain long keyword. So it consumes Java heap space uselessly.

Can I remove hits.hits.sort field itself or the keyword text in the field by any option?


Welcome! I don't think you can. That being said I don't think that displaying 10 sort values is the problem.

You should read

It says that you are loading in memory all the sort values. Even though you are displaying only 10 afterwards.

May be using index sorting could help? See

Thank you very much!

Sorry for my incomplete explanation. we used bigger size than default value (10).
So the size of the response came to an issue.

After my post, I found filter_path parameter. It may be the solution for what we wanted to do.

May be but the filtering will not happen early though. So big objects will still being built in memory.

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