Request body or source parameter is required – How to solve this Elasticsearch error

Opster Team

February-21, Version: 1.7-8.0

To understand why this error appeared and how to remedy the errors in your query, you should run the AutoOps for Elasticsearch.

This guide will help you understand issues realted to the log “request body or source parameter is required”. To get started, read the general overview on common issues and tips related to the Elasticsearch concepts: rest, request and source.

Background

The Analyze API is used to perform analysis on a text string and return the resulting tokens. The above exception arises when the cURL request of Analyze API is malformed. The proper format, as detailed below in the “How to fix” section, is required to get the tokens using this API.

How to reproduce this exception

In the cURL format, if the Analyze request is written like this:

Hit the Analyze API:

curl -XGET "localhost:9200/my-index/_analyze?analyzer=standard&pretty" -H -d "Opster"

Then the response generated will be:

{
 "error": {
   "root_cause": [
     {
       "type": "parse_exception",
       "reason": "request body or source parameter is required"
     }
   ],
   "type": "parse_exception",
   "reason": "request body or source parameter is required"
 },
 "status": 400
}

How to fix this exception

The cURL request is malformed. The query can be modified in the following way:

In cURL format:

curl -XGET "http://localhost:9800/my-index/_analyze?pretty" -H 'Content-Type: application/json' -d '{ "analyzer": "standard", "text": "Opster" }'

The equivalent request in the Kibana Dev Tools format is:

GET /my-index/_analyze?pretty
{
 "analyzer" : "standard",
 "text" : "opster"
}

The tokens generated from the above request are:

{
 "tokens": [
   {
     "token": "opster",
     "start_offset": 0,
     "end_offset": 4,
     "type": "<ALPHANUM>",
     "position": 0
   }
 ]
}

To learn more about tokens, you can refer to text analysis for more information.

Log Context

Log “request body or source parameter is required”classname  is RestRequest.java We extracted the following from Elasticsearch source code for those seeking an in-depth context :

* Get the content of the request or the contents of the {@code source} param or throw an exception if both are missing.
 * Prefer {@link #contentOrSourceParamParser()} or {@link #withContentOrSourceParamParserOrNull(CheckedConsumer)} if you need a parser.
 */
 public final Tuple contentOrSourceParam() {
 if (hasContentOrSourceParam() == false) {
 throw new ElasticsearchParseException("request body or source parameter is required");
 } else if (hasContent()) {
 return new Tuple<>(xContentType.get(); requiredContent());
 }
 String source = param("source");
 String typeParam = param("source_content_type");

 

Watch product tour

Try AutoOps to find & fix Elasticsearch problems

Analyze Your Cluster
Skip to content