I am inserting data to a elastic search using CURL, it works fine when i insert with a fixed data. I am trying to Get Current DateTime and assign to a variable and use with the
Inside your string, change
"CreateDate": "2015-01-01T15:23:42",
to
"CreateDate": "'"$(date +%Y-%m-%dT%H:%M:%S)"'",
There, I terminated the '
string and started a "
string with the $(date)
inside it. Otherwise, it would not get executed, but just passed to curl
as a string.
You can also assign it to a variable beforehand and use it later like this:
now=$(date +%Y-%m-%dT%H:%M:%S)
...
"CreateDate": "'"$now"'",
Change
curl -XPUT 'http://localhost:9200/nondomain_order/orders/'+$number+'' -d '{
into
curl -XPUT 'http://localhost:9200/nondomain_order/orders/'"$number" -d '{
Bash concatenation is just two strings one after another without a space between them. Otherwise, it would query URLS like http://localhost:9200/nondomain_order/orders/+0123456789+
instead of http://localhost:9200/nondomain_order/orders/0123456789
(Here, I protected the number
variable against expansion with double quotes for safety if it ever changes)