Getting illegal_argument_exception", "reason": "Fielddata is disabled on text fields by default elastic search

I am getting this query when i try to run below query from Postman

{ "error": { "root_cause": [ { "type": "illegal_argument_exception", "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [ID] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead." }

Here is the request

{

    "size": 11,

    "query": {

        "bool": {

            "filter": [

                {

                    "bool": {

                        "must": [

                            {

                                "term": {

                                    "search.doc.TypeId": {

                                        "value": 1,

                                        "boost": 1.0

                                    }

                                }

                            }

                        ],

                        "adjust_negative": true,

                        "boost": 1.0

                    }

                }

            ],

            "adjust_negative": true,

            "boost": 1.0

        }

    },

    "sort": [

        {

            "ID": {

                "order": "desc"

            }

        }

    ]

}

Based on the error it seems that the objectID field is of text type. By default, field data is disabled on text fields.

So, according to the error, first, you need to modify your index mapping, so that the text field have field data enabled. Modify your index mapping, as shown below

PUT <index-name>/_mapping
{
  "properties": {
    "objectID": {
      "type": "text",
      "fielddata": true
    }
  }
}

Now use the same search query as given in the question, to get the desired results.