【发布时间】:2019-11-19 07:49:45
【问题描述】:
当我运行这个命令时,它会将$line 直接发布到 Elasticsearch 中,而不是 file.txt 的行中
cat file.txt | while IFS= read -r line; do curl -d '{ "field" : "$line" }' -H "Content-Type: application/json" -POST "http://localhost:9200/indexname/doc"; done;
file.txt 包括:
This is line one.
This is line two.
This is line three.
这是 Centos 7 上的 Elasticsearch 7.2。
我尝试像 \$line 和 ($line) 或 "$line" 一样转义 $line
但它发布了\$line 和($line) 或"$line" 的实际值
要放入 Elasticsearch 的预期数据:
{ "field" : "This is line one." }
{ "field" : "This is line two." }
{ "field" : "This is line three." }
将实际数据放入 Elasticsearch { "field" : "$line" }
【问题讨论】:
标签: bash elasticsearch curl while-loop cat