码迷,mamicode.com
首页 > 其他好文 > 详细

elasticsearch 自定义_id

时间:2016-11-11 22:44:30      阅读:392      评论:0      收藏:0      [点我收藏+]

标签:str   als   uuid   写入   zed   生成   dex   ping   errors   

elasticsearch 自定义ID:

 

curl -s -XPUT localhost:9200/web -d ‘
{
    "mappings": {
        "blog": {
            "_id": {
                "path": "uuid"
            },
            "properties": {
                "title": {
                    "type":   "string",
                    "index":  "analyzed"
                }
            }
        }
    }
}‘

启动本地es,然后写入数据,data2.json:

{ "index":  { "_index": "web", "_type": "blog", "_id": "123" }}
{"title":    "But we can update it" }
{ "index":  { "_index": "web", "_type": "blog", "_id": "123" }}
{ "title":    "But we can update it" }
{ "index":  { "_index": "web", "_type": "blog"}}
{ "title":    "But we can update it", "uuid": "3210"}

通过批量插入上述数据:

curl -s -XPOST localhost:9200/_bulk --data-binary @data2.json
{"took":3,"errors":false,"items":[{"index":{"_index":"web","_type":"blog","_id":"123","_version":5,"status":200}},
{"index":{"_index":"web","_type":"blog","_id":"123","_version":6,"status":200}},
{"index":{"_index":"web","_type":"blog","_id":"3210","_version":3,"status":200}}]}

可以看到新生成的文档_id为uuid的数值!

 

elasticsearch 自定义_id

标签:str   als   uuid   写入   zed   生成   dex   ping   errors   

原文地址:http://www.cnblogs.com/bonelee/p/6055502.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!