简体   繁体   English

Mysql Query 到 Elasticsearch Query 的转换

[英]Mysql Query to Elasticsearch Query conversion

How to convert the below Mysql query to Elasticsearch query?如何将下面的 Mysql 查询转换为 Elasticsearch 查询?

SELECT  
distinct t.id as 'Task ID',
cust.name as 'Customer' ,
ticketType.type as 'Task Type',
t.created_time as 'Created Date',
ci.name as 'Asset'
FROM ticket t
JOIN reported_master AS rs ON reported_issue_type.id = t.reported_issuetype_id
JOIN ci_master AS ci ON ci.id = t.primary_ci 
JOIN ticket_source_master  AS source_master ON source_master.id = t.ticket_source_id          
and source_master.name='Bus'
where t.engagement_id=14653  and t.created_time >= DATE_SUB(NOW(), INTERVAL 24 HOUR);

I am new to ES and don't know how to write a query for join condition.我是 ES 新手,不知道如何编写连接条件查询。

As stated in the comments section, you can't do JOINs in elasticsearch like/as convenient as in SQL/a relational database.正如评论部分所述,您不能像在 SQL/关系数据库中那样/那样方便地在 elasticsearch 中执行 JOIN。

However, you may want to take a look at the SQL Translate API which translates SQL-Statements into native Elasticsearch queries.但是,您可能需要查看SQL Translate API ,它将 SQL 语句转换为原生 Elasticsearch 查询。

Furthermore I suggest to take a look at the Join datatype and Joining Queries to understand the mechanism/requirements for joining documents in Elasticsearch.此外,我建议查看Join 数据类型Joining Queries以了解在 Elasticsearch 中加入文档的机制/要求。 But I strongly recommend changing your data structure instead of joining documents.但我强烈建议更改您的数据结构而不是加入文档。

Hope this helps.希望这可以帮助。

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

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