java.lang.OutOfMemoryError: Java heap space

when using prefix query with large text give exception then service will stop.

{
  "track_total_hits": true,
  "from": 0,
  "query": {
    "bool": {
      "minimum_should_match": 1,
      "must": [
        {
          "bool": {
            "must": [
              {
                "prefix": {
                  "form.reason": {
                    "value": "with large text .....",
                    "case_insensitive": true
                  }
                }
              }
            ]
          }
        }
      ],
      "should": [
        {
          "nested": {
            "path": "task",
            "query": {
              "term": {
                "form.userId": {
                  "value": 12
                }
              }
            }
          }
        }
      ]
    }
  },
  "size": 10,
  "sort": [
    {
      "createdDate": {
        "order": "desc"
      }
    }
  ]
}

you need to explain a bit more about your question.
What is the exception?
Check the logs to see full stack trace and share that here.