How to write elastic search query for one required parameter and another optional paramater

I need to create an Elasticsearch endpoint with two paramater : Session(required field),CallType(Optional) which returns call details bewteen Teacher and student. I can search for specific session with below details. My query will also have call duration field which will calculate total duration of call between first and last CallDateTime

Search response should be like

{
  "CallDuration": 10,
  "Session": "g4cld594-7a9d-4177-919c-df62cab73a79",
  "StudentName": "Andy White",
  "TeacherName": "Annie Frank",
  "CallTypes": [
    {
      "CallType": "TeacherJoined",
      "CallDateTime": "2023-01-01T14:50:57.403083+05:00"
    },
   {
      "CallType": "StudentJoined",
      "CallDateTime": "2023-01-02T14:50:57.403083+05:00"
    },
    {
      "CallType": "TeacherJoined",
      "CallDateTime": "2023-01-01T14:55:57.403083+05:00"
    },
   
  ]
}

How can I modify below endpoint query to achieve desired response?

public async Task<List<CallDetailsResponse>> SearchCallDetails(string session,string callType)
        {
            
            var results = await client.SearchAsync<CallDetailsResponse>(s => s
                 .From(0)
                 .Size(10)
                 .Query(q => q
                     .Match(m => m
                         .Field(f => f.Session)
                         .Query(session)
                     )
                 ));
            return (CallDetailsResponse)results.Documents?.ToList();
        }

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.