使用Kibana或API导入数据到Elasticsearch 使用API导入数据 使用bulk API通过cURL命令导入数据文件,如下操作以JSON数据文件为例。 说明 使用API导入数据文件时,建议导入的数据文件大小不能超过50MB。 1.登录即将接入集群的弹性云主机。 接入集群的详细操作指导请参见接入集群章节中的 在同一VPC内的弹性云主机,直接调用Elasticsearch API。 2.执行如下命令,导入JSON数据。 其中, { Private network address and port number of the node } 需替换为集群中节点的内网访问地址和端口号,当该节点出现故障时,将导致命令执行失败。如果集群包含多个节点,可以将 { Private network address and port number of the node } 替换为集群中另一节点的内网访问地址和端口号;如果集群只包含一个节点,则需要将该节点修复之后再次执行命令进行导入数据。test.json为导入数据的json文件。 curl X PUT " network address and port number of the node} /bulk" H 'ContentType: application/json' databinary @test.json 说明 其中,X参数的参数值为命令,如“X PUT”,H参数的参数值为消息头,如“H 'ContentType: application/json' databinary @test.json”。添加的k参数时,请勿将k参数放置在参数与参数值之间。 示例 : 将“testdata.json”数据文件中的数据导入至Elasticsearch集群,此集群未进行通信加密,其中一个节点内网访问地址为“192.168.0.90”,端口号为“9200”。其中testdata.json文件中的数据如下所示: {"index":{"index":"mystore","type":"products"}} {"productName": "2019秋装新款文艺衬衫女装","size":"M"} {"index":{"index":"mystore","type":"products"}} {"productName": "2019秋装新款文艺衬衫女装","size":"L"} 导入数据的操作步骤如下所示: a. 可执行以下命令,创建mystore索引。 7.x之前版本 curl X PUT H 'ContentType:application/json' d ' { "settings": { "numberofshards": 1 }, "mappings": { "products": { "properties": { "productName": { "type":"text" }, "size": { "type":"keyword" } } } } }' 7.x之后版本 curl X PUT H 'ContentType:application/json' d ' { "settings": { "numberofshards": 1 }, "mappings": { "properties": { "productName": { "type": "text" }, "size": { "type":"keyword" } } } }' b. 执行以下命令,导入testdata.json文件中的数据。 curl X PUT " H 'ContentType: application/json' databinary @testdata.json