An elegy is simply a type of poem, often considered a lyrical poem but in the elegy itself, there are no specific rules about the form that it can take. It is simply a term to denote the fact that the verse is about mourning or the loss of someone or even something.
An elegy can be set to music, but doesn't have to be. I have pasted in a link to some thoughts about how one ought to compose an elegy, but again, there are no definitive rules about what an elegy must be or what form it must take.
Elegy in the beginning was related to a particular kind of prosodic or metrical structure that was called the elegiac rhythm but now it is regarded as a thematic notion. It is a lyric poem/song of lament, mourning the death of a near one or beloved or at a deeper level even a phenomenon, an emotion, a state of the matter, an ideology or an era.
Some of the conventions of pastoral elegy are--
1. The mourning in the form of a dialogue between two shepherds.
2. The active participation of rural nature in the mourning.
3. The idealization of the dead figure of the shepherd.
4. The description of some funeral procession or other commemorative measure.
5. The rather Christian conclusion where the elegiac emotions of mourning and melancholia are undercut by the Christian rhetoric of belief where death is a happy occasion, a true homecoming of the soul after the finite sojourn of mortal life on the earth or a reunion with the God. This divine optimism is made to counter the elegiac mood in this final movement of transcendence.