Curl single quotes vs. double quotes


(Boudewijn) #1

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"

cURL - Could not get simple GET to work
(David Pilato) #2

On? Windows? Linux?

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


#3

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.


(Val Crettaz) #4

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


(Boudewijn) #5

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.


(Val Crettaz) #6

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


(Boudewijn) #7

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
   mmand

(Val Crettaz) #8

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


(Boudewijn) #9

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


(Val Crettaz) #10

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...

(Boudewijn) #11

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)


(Val Crettaz) #12

Glad it helped!


(system) #13

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