向Solr的Collection(Core)上传document的方式有很多,Solr支持的document格式也有很多,本次介绍使用curl向solr提交Json document的2种方式。
方式一:上传json文件
上传多个json document,一般都是采用直接上传json文件来实现,这样不会使curl请求的内容太长,主要命令如下:
curl 'http://localhost:8983/solr/userinfo/update?commit=true' --data-binary @/home/xx/Documents/kettleT/userinfo_1.json -H 'Content-type:application/json'
方式二:上传单个json document
可以在curl请求中,直接加入json document,主要命令如下:
curl -X POST -H 'Content-Type: application/json'
'http://localhost:8983/solr/my_collection/update/json/docs' --data-binary '
{
"id": "1",
"title": "Doc 1"
}'