How can we use BoolenTermsAggregate in Asp.net

var searchRequest = new SearchRequest<InboxPatientDataFromES>(indexName)
{
    Size = 0,
    Query = new BoolQuery
    {
        Must = mustQueries
    },
    Aggregations = new AggregationDictionary
    {
     {
        "patientname_agg", new TermsAggregation("patientname_agg")
        {
            Field = "patientname.keyword",
            Size = 100,
           Order = new List<KeyValuePair<Field, SortOrder>>
                        {
                            new KeyValuePair<Field, SortOrder>("_key", SortOrder.Asc)
                        },
            Aggregations = new AggregationDictionary
            {
              {
                "patientnhi_agg", new TermsAggregation("patientnhi_agg")
                {
                    Field = "nhinumber.keyword",
                    Size = 100,
                    Aggregations = new AggregationDictionary
            {
              {
                "isabnormal_agg", new TermsAggregation("isabnormal_agg")
                {
                    Field = "isabnormal.keyword",
                    Size = 2,
                    Aggregations = new AggregationDictionary
            {
              {
                "isnormal_agg", new TermsAggregation("isnormal_agg")
                {
                    Field = "isnormal.keyword",
                    Size = 2,
                    Aggregations = new AggregationDictionary
                    {
                        {
                            "patientindiciid_aggregation", new TermsAggregation("patientindiciid_aggregation")
                            {
                                Field = "patientindiciid",
                                Size = 100,
                                Aggregations = new AggregationDictionary
                                {
                                    {
                                        "top_hits", new TopHitsAggregation("top_hits")
                                        {
                                            Size = 100,
                                            Source = new Elastic.Clients.Elasticsearch.Core.Search.SourceConfig(new Elastic.Clients.Elasticsearch.Core.Search.SourceFilter
                                            {
                                                Includes = new [] { "patientname", "providername", "messagesubject", "foldername", "resultdate","diagnosticcomments" }
                                            })
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                        }
                    }
                }
                        }
                    
                    }
                }
              }
            }
        }
     }
    }
};

var response = await _client.SearchAsync<InboxPatientDataFromES>(searchRequest);
ElasticAggregationModelForSkinHistory result = new ElasticAggregationModelForSkinHistory();
List<PatientForInboxData> data = new List<PatientForInboxData>();

if (response.IsValidResponse)
{

    if (response.Aggregations.TryGetValue("patientname_agg", out var patientNameAggregate))
    {
        var patientNameTerms = patientNameAggregate as StringTermsAggregate;
        if (patientNameTerms != null)
        {
            foreach (var nameBucket in patientNameTerms.Buckets)
            {
                var patientName = nameBucket.Key.ToString();
                if (nameBucket.TryGetValue("patientnhi_agg", out var patientNhiAggregate))
                {
                    var patientNhiTerms = patientNhiAggregate as StringTermsAggregate;
                    if (patientNhiTerms != null)
                    {
                        foreach (var nhiBucket in patientNhiTerms.Buckets)
                        {
                            var patientNhi = nhiBucket.Key.ToString();
                            if (nhiBucket.TryGetValue("isabnormal_agg", out var patientisabnormalAggregate))
                            {
                                var patientisabnormalAggregateTerms = patientisabnormalAggregate as BooleanTermsAggregate;
                                if (patientisabnormalAggregateTerms != null)
                                {
                                    foreach (var isabnormalBucket in patientisabnormalAggregateTerms.Buckets)
                                    {
                                        var PatientisAbnormalBucket = isabnormalBucket.Key.ToString();
                                        if (isabnormalBucket.TryGetValue("isnormal_agg", out var patientisnormalAggregate))
                                        {
                                            var patientisnormalAggregateTerms = patientisnormalAggregate as StringTermsAggregate;
                                            if (patientisnormalAggregateTerms != null)
                                            {
                                                foreach (var isnormalBucket in patientisnormalAggregateTerms.Buckets)
                                                {
                                                    var PatientisNormalBucket = isnormalBucket.Key.ToString();

                                                    if (isnormalBucket.TryGetValue("patientindiciid_aggregation", out var bucketAggregate))
                                                    {
                                                        var termsAggregate = bucketAggregate as LongTermsAggregate;
                                                        if (termsAggregate != null)
                                                        {
                                                            foreach (var bucket in termsAggregate.Buckets)
                                                            {
                                                                PatientForInboxData patient = new PatientForInboxData
                                                                {
                                                                    patientindiciid = bucket.Key.ToString(),
                                                                    patientname = patientName, // Assign patient name
                                                                    patientnhi = patientNhi,    // Assign patientnhi 
                                                                    abnormal = PatientisAbnormalBucket,
                                                                    normal = PatientisNormalBucket,
                                                                    InboxRecords = new List<InboxRecords>()
                                                                };

                                                                if (bucket.TryGetValue("top_hits", out var topDocuments))
                                                                {
                                                                    var topDocumentsData = topDocuments as TopHitsAggregate;
                                                                    foreach (var hit in topDocumentsData.Hits.Hits)
                                                                    {
                                                                        string elasticDocJson = hit.Source.ToString();
                                                                        var record = JsonSerializer.Deserialize<InboxRecords>(elasticDocJson);
                                                                        if (record != null)
                                                                        {
                                                                            patient.InboxRecords.Add(record);
                                                                        }
                                                                    }
                                                                }

                                                                data.Add(patient);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    result.PatientsData = data;

    return result;
}

This is my code i use the Aggregation but the issue is when i access the "isabnormal_agg" Elastic.Clients.Elasticsearch does not support the BoolenTermsAggregation then how can i access the "isabnormal_agg" field value. if anyone know about it kindly share because for this little problem i am stuck in the project.

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