简体   繁体   English

如何索引 Elasticsearch 的标准化 SQL 数据库

[英]How to index normalized SQL database for Elasticsearch

I have already indexed a database (SQL) with a single table which is in sync with its Elasticsearch index.我已经用一个与其 Elasticsearch 索引同步的表为数据库 (SQL) 建立了索引。 Now I want to index a database with multiple normalized tables.现在我想用多个规范化表索引一个数据库。 So, how should I index those tables?那么,我应该如何索引这些表呢? Should I write multiple JOIN queries in my logstash file during indexing the database tables, or should I index each table one by one and perform multiple index search?我应该在索引数据库表期间在我的logstash文件中编写多个JOIN查询,还是应该一个一个地索引每个表并执行多个索引搜索? But for second way, I do not know how to form elasticsearch query for the relevant SQL queries.但是对于第二种方式,我不知道如何为相关的 SQL 查询形成 elasticsearch 查询。 I am new to Elasticsearch.我是 Elasticsearch 的新手。 So any guidance for the problem would be appreciated.因此,我们将不胜感激任何有关该问题的指导。 Here I am also attaching the schema of the database.在这里,我还附加了数据库的架构。 One more thing, I am using PHP client for searching and displaying data.还有一件事,我正在使用 PHP 客户端来搜索和显示数据。 员工数据库架构

First of all, everything will depend on how you want to build your indexes in elasticsearch, that is, if you want an index for each table or an index for several tables.首先,一切都取决于您希望如何在 elasticsearch 中构建索引,也就是说,您是否需要为每个表创建索引或为多个表创建索引。
My advice is:我的建议是:

  1. Create a trigger in the database to audit every change (insert, update, delete) and store it in a news table along with the action and a state.在数据库中创建一个触发器来审核每个更改(插入、更新、删除)并将其与操作和 state 一起存储在新闻表中。
  2. Create a view for each type of novelty or table, this view will depend on how you want to index everything.为每种类型的新奇事物或表格创建一个视图,该视图将取决于您希望如何索引所有内容。
  3. Use jdbc to call the views says the state is equal to pending (raw).使用 jdbc 调用视图说 state 等于挂起(原始)。
  4. Use filters to normalize your data and adjust it to your elasticsearch structure.使用过滤器标准化您的数据并将其调整为您的 elasticsearch 结构。
  5. Use JDBC output to update the database by setting the newness to processed to prevent it from appearing in the query.使用 JDBC output 通过将 newness 设置为处理来更新数据库,以防止它出现在查询中。

In addition to these points, my recommendation is that you have those tables in a single index, for example, employee, where you can create different nested objects for each entity in the database, such as department, etc. where you could add the code tags and description of each one.除了这些点之外,我的建议是您将这些表放在一个索引中,例如,员工,您可以在其中为数据库中的每个实体创建不同的嵌套对象,例如部门等。您可以在其中添加代码每个标签和描述。 You can check if it has not been clear您可以检查是否还不清楚

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM