简体   繁体   中英

Mysql Query to Elasticsearch Query conversion

How to convert the below Mysql query to Elasticsearch query?

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.

As stated in the comments section, you can't do JOINs in elasticsearch like/as convenient as in SQL/a relational database.

However, you may want to take a look at the SQL Translate API which translates SQL-Statements into native Elasticsearch queries.

Furthermore I suggest to take a look at the Join datatype and Joining Queries to understand the mechanism/requirements for joining documents in Elasticsearch. But I strongly recommend changing your data structure instead of joining documents.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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