首页 > 其他 > 详细

elasticsearch 自定义_id

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

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!