ElasticSearch5:Document id的手动指定和自动生成两种解析
2017-12-28 09:43
549 查看
1.document的id
1)根据应用情况来说,是否满足是否指定document id的手动指定,一般情况,是从某些其他的系统中,导入一些数据到es时,会采用这种方式,就是使用系统中已有数据的唯一标识,作为es中document的id,举个例子,比如说我们现在在开发一个电商网站,做搜索功能,或者oa系统的员工查询,这个时候,数据首先会在网站的系统中的数据库中,会先有一份,此时就肯定会有一个数据库的primary key(自增长,uuid,业务id),此时就比较适合采用数据在数据库中已有的primary key
语法:
PUT /index/type/id
{
"xxx":"xxx"
}
例子:
PUT /ecommerce/product/4
{
"name":"yayale yagao",
"desc":"gaoxiao meibai",
"price":100,
"producer":"yayale producer",
"tags":[
"fangzhu","meibai","qingxin"
]
}
执行结果:
{
"_index": "ecommerce",
"_type": "product",
"_id": "4",
"_version": 2,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 2,
"_primary_term": 3
}
2)如果数据主要存储到es中,那么就可以使用document中的自动生成的id
语法:不写id
POST /index/type
{
"xxx":"xxx"
}
例子:
POST /test_index/salesOrder/
{
"OrderProductIds":"5"
}
执行结果:生成的自动id是20的guid
{
"_index": "test_index",
"_type": "salesOrder",
"_id": "1l3zmmABEP2XuYqp4PmX",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1
}
例子2:
POST /ecommerce/product
{
"name":"heiren yagao",
"desc":"gaoxiao meibai",
"price":100,
"producer":"heiren producer",
"tags":[
"fangzhu","meibai","qingxin"
]
}
执行结果:
{
"_index": "ecommerce",
"_type": "product",
"_id": "1131mmABEP2XuYqpoflk",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 3,
"_primary_term": 3
}
1)根据应用情况来说,是否满足是否指定document id的手动指定,一般情况,是从某些其他的系统中,导入一些数据到es时,会采用这种方式,就是使用系统中已有数据的唯一标识,作为es中document的id,举个例子,比如说我们现在在开发一个电商网站,做搜索功能,或者oa系统的员工查询,这个时候,数据首先会在网站的系统中的数据库中,会先有一份,此时就肯定会有一个数据库的primary key(自增长,uuid,业务id),此时就比较适合采用数据在数据库中已有的primary key
语法:
PUT /index/type/id
{
"xxx":"xxx"
}
例子:
PUT /ecommerce/product/4
{
"name":"yayale yagao",
"desc":"gaoxiao meibai",
"price":100,
"producer":"yayale producer",
"tags":[
"fangzhu","meibai","qingxin"
]
}
执行结果:
{
"_index": "ecommerce",
"_type": "product",
"_id": "4",
"_version": 2,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 2,
"_primary_term": 3
}
2)如果数据主要存储到es中,那么就可以使用document中的自动生成的id
语法:不写id
POST /index/type
{
"xxx":"xxx"
}
例子:
POST /test_index/salesOrder/
{
"OrderProductIds":"5"
}
执行结果:生成的自动id是20的guid
{
"_index": "test_index",
"_type": "salesOrder",
"_id": "1l3zmmABEP2XuYqp4PmX",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1
}
例子2:
POST /ecommerce/product
{
"name":"heiren yagao",
"desc":"gaoxiao meibai",
"price":100,
"producer":"heiren producer",
"tags":[
"fangzhu","meibai","qingxin"
]
}
执行结果:
{
"_index": "ecommerce",
"_type": "product",
"_id": "1131mmABEP2XuYqpoflk",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 3,
"_primary_term": 3
}
相关文章推荐
- elasticsearch核心知识--15.document id的手动指定与自动生成两种方式解析
- hibernate自动生成uuid策略下手动指定id
- 【VBA】通过VBA自动解析指定工作薄,生成自己需要的数据表
- 【qtp脚本】实现自动创建目录并通过测试写字板生成指定个数的文件
- Solr6.6.0 自动生成ID
- tmx瓦片地图文件内容的解析与地图自动生成
- HEW中RX62N工程自动生成文件的解析
- 自动生成testbench的两种方法
- MyEeclipse_10部署项目文件(手动和自动两种)
- Eclipse编写Android程序时layout的xml里的id不能在R.java里自动生成
- Hibernate注解使用以及Spring整合 , hibernate 自动生成uuid类型的id 注解
- google gerrit repo, git commit如何自动生成Change-Id
- iOS崩溃日志之手动解析与自动解析
- Oracle 自动生成标识列, 比如订单编号,学生ID
- .net2.0 生成缩略图,与指定比例不等自动补白边的方法
- ASP.NET 4.0 ListView等容器控件中获取ClientID值与HTML中自动生成ID字符串不一样问题。
- oracle中利用trigger,sequence自动生成ID
- 如何使用java自动生成数据表id,java.util.UUID类
- 关于Gridview自动生成列后,手动设定的模板列位置问题解决方案