elasticsearch的父子_Elasticsearch 父子关系维护和检索案例分享

Elasticsearch 父子关系维护和检索案例分享,展示has_child和has_parent的基本用法。

本案例针对elasticsearch 5.x进行父子关系进行介绍,6.x版本通过join type来实现父子关系检索,参考文档后面提供的demo。

本文涉及技术点:

1.删除和创建公司/雇员父子关系的索引表

2.bulk批量导入json格式数据

3.ormapping方式bulk批量导入数据

4.采用@ESId指定文档_id

5.采用@ESParentId制定子文档的parent信息

6.基本的has_child和has_parent公司/雇员父子关系检索

1.准备工作

2.定义dsl文档

建立dsl配置文件-esmapper/indexparentchild.xml

"settings": {

"number_of_shards": 6,

"index.refresh_interval": "5s"

},

"mappings": {

"company": { ##公司

"properties": {

"name": {

"type": "text",

"fields": { ##dsl注释 定义精确查找的内部keyword字段

"keyword": {

"type": "keyword"

}

}

},

"city": {

"type": "text",

"fields": { ##dsl注释 定义精确查找的内部keyword字段

"keyword": {

"type": "keyword"

}

}

},

"country": {

"type": "text",

"fields": { ##dsl注释 定义精确查找的内部keyword字段

"keyword": {

"type": "keyword"

}

}

},

"companyId": {

"type": "keyword"

}

}

},

"employee":

{ ##雇员

"_parent": {##定义雇员和公司父子关联关系

"type": "company"

},

"_routing": {

"required": false

},

"properties": {

"name": {

"type": "text",

"fields": { ##dsl注释 定义精确查找的内部keyword字段

"keyword": {

"type": "keyword"

}

}

},

"birthday": {

"type": "date",

"format":"yyyy-MM-dd||epoch_millis"

},

"hobby": {

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值