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

In ElasticSearch bulk upload, how do I insert data with a single quote?

如何将包含单引号的数据批量插入到 ElasticSearch 中?这是我正在尝试做的一个例子。

curl -XPUT 'http://localhost:9200/example1/example2/_bulk' -d'¬
{ "delete" : { "_id" : "1" } } ¬
{ "create" : { "_id" : "1" } } ¬
{ "name" : "John's House" }¬ '

您只需像这样将单引号加倍即可:

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

您不能在单引号中嵌入单引号。 但是你可以打破单引号字符串然后 "insert" 一个单引号:

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