1

I would like to make cURL/Elasticsearch understand HTTP query parameters passed as normal strings while being url encoded by the command.

If I run this HTTP GET via cURL to submit the query to Elasticsearch:

curl \
  -H 'Content-Type: application/json' \
  -XGET '127.0.0.1:9200/movies/movie/_search?q=%2Byear%3A%3E1980+%2Btitle%3Astar%20wars&pretty'

Then I am able to retrieve the expected documents.

However if I run this cURL query:

curl \
   -H 'Content-Type: application/json' \
   --data-urlencode "pretty" \
   --data-urlencode "q=+year:>1980 +title:star wars&pretty" \
   -XGET '127.0.0.1:9200/movies/movie/_search'

Then I get this error:

{
    "error": {
        "root_cause": [{
            "type": "json_parse_exception",
            "reason": "Unrecognized token 'pretty': was expecting ('true', 'false' or 'null')\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@7856627; line: 1, column: 8]"
        }],
        "type": "json_parse_exception",
        "reason": "Unrecognized token 'pretty': was expecting ('true', 'false' or 'null')\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@7856627; line: 1, column: 8]"
    },
    "status": 500
}

I am using:

  • cURL version 7.47.0 which should understand the command parameter --data-urlencode
  • Elasticsearch 6.3.1

1 Answer 1

1

--data-urlencode will send a POST and URL encode the body. You have to use -G or --get in order to send a GET request & append the data specified with --data-urlencode in the URL :

curl -G -v \
     -H 'Content-Type: application/json' \
     --data-urlencode "pretty=true" \
     --data-urlencode "q=+year:>1980 +title:star wars" \
     '127.0.0.1:9200/movies/movie/_search' 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.