在ElasticSearch批量上传中,如何使用单引号插入数据?

时间:2017-06-10 00:59:38

标签: bash curl elasticsearch bulkinsert

如何将数据批量插入包含数据内单引号的ElasticSearch?这是我想要做的一个例子。

if (cpu_features->max_cpuid >= 7)

2 个答案:

答案 0 :(得分:1)

您无法在单引号中嵌入单引号。 但是你可以打破单引号字符串,然后在那里“插入”单引号:

curl -XPUT 'http://localhost:9200/example1/example2/_bulk' -d'¬
{ "delete" : { "_id" : "1" } } ¬
{ "create" : { "_id" : "1" } } ¬
{ "name" : "John'\''s House" }'
                ^ ^^
                | ||
                | |└ start new single-quoted string
                | └- escaped single quote outside of single-quoted string
                └--- close previously started single-quoted string

答案 1 :(得分:0)

你只需要将单引号加倍:

curl -XPOST 'http://localhost:9200/example1/example2/_bulk' -d'
{ "delete" : { "_id" : "1" } }
{ "create" : { "_id" : "1" } }
{ "name" : "John''s House" }'
                 ^
                 |
       add a second single quote