例如 :
curl -XPUT 'http://localhost:9200/test/users/2' -d '{ "firstname" : "test" }'
Run Code Online (Sandbox Code Playgroud)
只插入一条记录.
如何在一个查询中插入多个记录?
您需要使用elasticsearch Bulk API.它允许您通过一个请求插入多个项目.请求被POST到特殊端点/_bulk,如下所示:
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{ "field1" : "value1" }
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "2" } }
{ "field1" : "value2" }
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "3" } }
{ "field1" : "value3" }
Run Code Online (Sandbox Code Playgroud)
我没有足够的业力来评论@Tadzys,但是,是的,在没有 id 的情况下将文档批量插入到一个或多个索引似乎是可行的。请参阅Elasticsearch:批量插入示例中的“在同一请求中插入属于不同类型和索引的文档” 。
从引用的页面:
POST http://path.to.your.cluster/_bulk
{ "index":{ "_index": "myIndex", "_type": "person" } }
{ "name":"john doe","age":25 }
{ "index":{ "_index": "myOtherIndex", "_type": "dog" } }
{ "name":"fido","breed":"chihuahua" }
Run Code Online (Sandbox Code Playgroud)
“示例适用于 Elasticsearch 版本 1.x、2.x,也可能适用于更高版本。”
| 归档时间: |
|
| 查看次数: |
11909 次 |
| 最近记录: |