es映射父子关系java_在ElasticSearch 6中创建父子关系时遇到问题

使用Elasticsearch 6.0,存在一些阻止父/子关系的根本性变化.

>一个索引不能包含多个类型.阅读更多here.

>父/子关系已被删除,因此

_parent字段也被删除.您必须使用连接字段

父母/子女.

父/子关系要求有两种不同的类型,并且两种类型都在同一索引中定义.既然您不能在一个索引中拥有多个类型,则无法以与5.x和先前版本中支持的方式相同的方式支持父/子关系.

您可以参考联接字段文档,了解如何对父/子关系执行类似操作.但是现在,您必须在同一类型的单个Elasticsearch索引中定义两种类型的文档.请参阅示例,该示例解释了如何使用连接字段here建模“1对多”关系(1个问题,与该问题相关的多个答案).

编辑:

使用join字段为Elasticsearch 6.x更新的示例如下所示.

删除现有索引(如果存在).

curl -XDELETE "http://localhost:9200/series"

使用连接字段创建新索引,建立特许经营权和加盟关系之间的联系关系.电影:

curl -XPUT "http://localhost:9200/series" -H 'Content-Type: application/json' -d'

{

"mappings": {

"doc": {

"properties": {

"join_field": {

"type": "join",

"relations": {

"franchise": "film"

}

}

}

}

}

}'

您的示例中更新的series.json将作为内联批量请求发送:

curl -XPOST "http://localhost:9200/_bulk" -H 'Content-Type: application/json' -d'

{ "create" : { "_index" : "series", "_type" : "doc", "_id" : "1"} }

{ "id": "1", "title" : "Star Wars", "join_field": "franchise" }

{ "create" : { "_index" : "series", "_type" : "doc", "_id" : "260", "routing" : "1" } }

{ "id": "260", "title" : "Star Wars: Episode IV - A New Hope", "year":"1977" , "genre":["Action", "Adventure", "Sci-Fi"], "join_field": {"name": "film", "parent": "1"} }

{ "create" : { "_index" : "series", "_type" : "doc", "_id" : "1196", "routing" : "1" } }

{ "id": "1196", "title" : "Star Wars: Episode V - The Empire Strikes Back", "year":"1980" , "genre":["Action", "Adventure", "Sci-Fi"], "join_field": {"name": "film", "parent": "1"} }

{ "create" : { "_index" : "series", "_type" : "doc", "_id" : "1210", "routing" : "1" } }

{ "id": "1210", "title" : "Star Wars: Episode VI - Return of the Jedi", "year":"1983" , "genre":["Action", "Adventure", "Sci-Fi"], "join_field": {"name": "film", "parent": "1"} }

{ "create" : { "_index" : "series", "_type" : "doc", "_id" : "2628", "routing" : "1" } }

{ "id": "2628", "title" : "Star Wars: Episode I - The Phantom Menace", "year":"1999" , "genre":["Action", "Adventure", "Sci-Fi"], "join_field": {"name": "film", "parent": "1"} }

{ "create" : { "_index" : "series", "_type" : "doc", "_id" : "5378", "routing" : "1" } }

{ "id": "5378", "title" : "Star Wars: Episode II - Attack of the Clones", "year":"2002" , "genre":["Action", "Adventure", "Sci-Fi", "IMAX"], "join_field": {"name": "film", "parent": "1"} }

{ "create" : { "_index" : "series", "_type" : "doc", "_id" : "33493", "routing" : "1" } }

{ "id": "33493", "title" : "Star Wars: Episode III - Revenge of the Sith", "year":"2005" , "genre":["Action", "Adventure", "Sci-Fi"], "join_field": {"name": "film", "parent": "1"} }

{ "create" : { "_index" : "series", "_type" : "doc", "_id" : "122886", "routing" : "1" } }

{ "id": "122886", "title" : "Star Wars: Episode VII - The Force Awakens", "year":"2015" , "genre":["Action", "Adventure", "Fantasy", "Sci-Fi", "IMAX"], "join_field": {"name": "film", "parent": "1"} }

'

上面的批量请求创建了一个与该特许经营相关的特许经营和多部电影.

要查询具有特许经营权ID = 1的所有电影,请使用以下父ID查询.

curl -XGET "http://localhost:9200/series/_search" -H 'Content-Type: application/json' -d'

{

"query": {

"parent_id": {

"type": "film",

"id": "1"

}

}

}'

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值