Curl single quotes vs. double quotes

I follow the Elastic tutorial and experience and error when I use the curl code provided in the tutorial:

curl -H "Content-Type: application/json" -XPOST 'localhost:9200/bank/account/_bulk?pretty&refresh' --data-binary "@accounts.json"

When I replace the single quotation marks with double quotation marks it works fine.

The problem not only occurs with the above command but everytime I use single quotation marks in curl. Am I the only one experiencing issues with the single quotation marks?

Another example. This doesn't work:

curl -XGET 'localhost:9200/_cat/health?v&pretty'

This works fine:

curl -XGET "localhost:9200/_cat/health?v&pretty"

On? Windows? Linux?

Anyway, it's always better using Kibana dev console. Much easier.

1 Like

I think this is because of the special ampersand character. It needs to be surrounded with double quotes because of its encoding.

You can also use CURL's -d option to specify parameters instead.

Both work well on Linux, so @boudewijnk is probably on Windows

I use Windows indeed.

I know I can get it running with double quotes. However, it's just a matter of convenience. I can easily copy the curl code from the tutorial, but when I need to replace the single quotes everytime, that's not that quick anymore.

Do you have any way to use PowerShell which accepts both single and double quotes?

I do have access to PowerShell.

However, using the command from my first message gives this response:

    PS C:\Users\Admin> curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/bank/account/_bulk?pr
etty&refresh' --data-binary "@accounts.json"
Invoke-WebRequest : Cannot bind parameter 'Headers'. Cannot convert the "Content-Type: application/json"
value of type "System.String" to type "System.Collections.IDictionary".
At line:1 char:9
+ curl -H "Content-Type: application/json" -XPOST 'http://localhost:920 ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.InvokeWebRequestCo

As @dadoonet mentioned, you're better off going through Kibana when working on Windows machines :slight_smile:

I was actually using kibana for most parts of the tutorial, but I couldn't figure out how to load the json data with kibana

In Kibana you can very well do a bulk call by copying the content of the accounts.json file

POST _bulk
...content of accounts.json goes here...

Thanks Val.

POST /bank/account/_bulk
...json content here...

Works indeed and is much faster than loading with curl (which takes a few minutes in which I cannot properly operate my machine)

Glad it helped!

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