HI All,
I have created an index via logstash using the jdbc driver for sql and the index has been made using the following query:
SELECT iDisID, iTopID, iPID, tblDiscussions.iUID, sSubject, dCreated, iViews, sQuestion, sTimestamp, bLocked, bArchived,
tblProfiles.sUserHRID, tblProfiles.sUserFname, tblProfiles.sUserSname, tblLUTopics.sTopName
FROM [KMNEW].[dbo].[tblDiscussions] Inner join [KMNEW].[dbo].[tblProfiles] on tblDiscussions.iUID = tblProfiles.iUID
INNER JOIN [KMNEW].[dbo].[tblLUTopics] ON tblDiscussions.iTopID = tblLUTopics.iTID
WHERE tblDiscussions.bActive=1 AND tblLUTopics.bActive=1
I now need to create a query against this index that will mimick the statement below. (I think this is probably too complex for elastic, but if anyone has a suggestion on how to approach this query would be good).
select idisid, ipid, itopid, tblDiscussions.iuid, sSubject, sQuestion, dCreated, tblLUTopics.sTopName, tblProfiles.sUserFname, tblProfiles.sUserSname, tblProfiles.sUserHRID from [dbo].[tblDiscussions]
INNER JOIN tblLUTopics ON tblDiscussions.iTopID = tblLUTopics.iTID
INNER JOIN [dbo].[tblProfiles] on tblProfiles.iUID = tblDiscussions.iUID
where ipid = 0
union all
select dd.idisid, dd.ipid, dd.itopid, dd.iUID, dd.sSubject, dd.sQuestion, dd.dCreated, tblLUTopics.sTopName, tblProfiles.sUserFname, tblProfiles.sUserSname, tblProfiles.sUserHRID
from tblDiscussions as dd
INNER JOIN tblLUTopics ON dd.iTopID = tblLUTopics.iTID
INNER JOIN [dbo].[tblProfiles] on tblProfiles.iUID = dd.iUID
cross apply (select distinct(ipid) from tblDiscussions where ipid != 0) as cr
cross apply (select min(idisid) as idisid from tblDiscussions group by ipid) as mm
where (dd.ipid = cr.ipid and dd.iDisID = mm.idisid )
group by dd.iDisID, dd.ipid, dd.itopid, dd.iUID, dd.sSubject, dd.sQuestion, dd.dCreated, tblLUTopics.sTopName, tblProfiles.sUserFname, tblProfiles.sUserSname, tblProfiles.sUserHRID
>