Elasticsearch 关系映射(一对一和一对多) [英] Elasticsearch relationship mappings (one to one and one to many)

查看:99
本文介绍了Elasticsearch 关系映射(一对一和一对多)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的弹性搜索服务器中,我有一个索引 http://localhost:9200/blog.
(博客)索引包含多种类型.

In my elastic search server I have one index http://localhost:9200/blog.
The (blog) index contains multiple types.

例如:http://localhost:9200/blog/postshttp://localhost:9200/blog/tags.

在标签类型中,我创建了超过 1000 个标签和 10 个帖子类型的帖子.

In the tags type I have created more than 1000 tags and 10 posts created in posts type.

例如:帖子

{   
    "_index":"blog",
    "_type":"posts",
    "_id":"1",
    "_version":3,
    "found":true,
    "_source" : {
        "catalogId" : "1",
       "name" : "cricket",
       "url" : "http://www.wikipedia/cricket"
    }
}

例如:标签

{   
    "_index":"blog",
    "_type":"tags",
    "_id":"1",
    "_version":3,
    "found":true,
    "_source" : {
        "tagId" : "1",
        "name" : "game"
    }
}

我想将现有标签分配给博客文章(即关系 => 映射).

I want to assign the existing tag to blog posts (i.e. relationship => mapping).

如何将标签分配给帖子映射?

How do I assign the tags to posts mapping?

推荐答案

您可以在 Elasticsearch 中使用 4 种方法来管理关系.Elasticsearch 博客文章 - 管理 Elasticsearch 内部的关系我建议您阅读整篇文章以获取有关每种方法的更多详细信息,然后选择最能满足您的业务需求同时保持技术适用性的方法.

There are 4 approaches that you can use within Elasticsearch for managing relationships. They are very well outlined in the Elasticsearch blog post - Managing Relations Inside Elasticsearch I would recommend reading the entire article to get more details on each approach and then select that approach that best meets your business needs while remaining technically appropriate.

以下是 4 种方法的重点.

Here are the highlights for the 4 approaches.

内部对象

  • 简单、快速、高效
  • 仅在保持一对一关系时适用
  • 无需特殊查询

嵌套

  • 嵌套文档彼此存储在同一个 Lucene 块中,这有助于提高读取/查询性能.读取嵌套文档比等效的父/子文档更快.
  • 更新嵌套文档(父级或嵌套子级)中的单个字段会强制 ES 重新索引整个嵌套文档.这对于大型嵌套文档来说可能非常昂贵
  • 交叉引用"嵌套文档是不可能的
  • 最适合不经常更改的数据

父/子

  • 子级与父级分开存储,但路由到同一个分片.所以父/子在读取/查询上的性能略低于嵌套
  • 父/子映射有一点额外的内存开销,因为 ES 在内存中维护一个连接"列表
  • 更新子文档不会影响父文档或任何其他子文档,这可能会为大型文档节省大量索引
  • 对父/子进行排序/评分可能很困难,因为 Has Child/Has Parent 操作有时可能不透明

非规范化

  • 您可以自己管理所有关系!
  • 最灵活、管理费用最高
  • 可能或多或少的性能取决于您的设置

这篇关于Elasticsearch 关系映射(一对一和一对多)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆