20

携程 Elasticsearch 数据同步实践

 3 years ago
source link: https://www.infoq.cn/article/0B4RzWOO8ldbt7XA6xc6
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

一、背景

Elasticsearch 是最近几年非常热门的分布式搜索和数据分析引擎,携程内部不仅使用 ES 实现了大规模的日志平台,也广泛使用 ES 实现了各个业务场景的搜索、推荐等功能。

本文聚焦在业务搜索的场景分享了我们在做数据同步方面的思考和实践,希望能对大家有所启发。

二、现状调研

数据同步是个很麻烦的事情,在各种论坛、分享中被大家反复讨论。

我们的需求大致包括全量、增量地从 Hive、MySql、Soa 服务、Mq 等不同类型的数据源获取数据,部分数据还需要进行一定的计算或者转换,然后近实时地同步到 ES 中,以被用户搜索到。

为了讨论方便,假定本文的场景是文章搜索的场景:

1)索引内容为文章,主要的信息保存在 article 表里;

2)每个文章关联了 tag,保存在 article_tag 表里;

3)tag 表里的 tagName 也需要进入 ES 索引,以便使用标签名字搜索文章;

在以前同步这样的数据进入 ES,单条文章的数据组装伪代码如下:

List <Long> tagIds = articleTagDao.query( "select tagId from article_tags where articleId=?" , articleId);

List <TagPojo> tags =tagDao.query( "select id, name from tags whereid in (?)" );

ArticleInEs articleInEs = new ArticleInEs();

articleInEs.setTagIds(tagIds);

articleInEs.setTagNames(tags.stream().filter(tag-> tagIds.contains(tag.getId())).map(TagPojo::getName).collect(Collectors.toList()));

复制代码


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK