Want to create a nest query to filter on optional field


{
	{
		"id": 8,
                "teamId": 0,
                "experience": 1,
		"companyName": "MyCompany"
	},
	{
		"id": 9,
                "teamId": 0,
                "experience": 1,
	},
	{
		"id": 10,
                "teamId": 1,
                "experience": 1,
	},
	{
		"id": 11,
                "teamId": 1,
                "experience": 1,
	        "companyName": "MyCompany"
	}
}

// Here is my nest query

List<Func<QueryContainerDescriptor<SearchClass>, QueryContainer>> filters = new List<Func<QueryContainerDescriptor<SearchClass>, QueryContainer>>();
filters.Add(n => n.Term(trm => trm.CompanyName.ToLower(), companyName.ToLower()))

jobProfiles = await _searchClient.SearchAsync<JobProfileSearch>(descriptor => descriptor
                    .From(pageIndex == 0 ? pageIndex : pageIndex * pageSize)
                    .Size(pageSize)
                    .Query(q => q
                        .Exists(e => e.Field(p => p.CompanyName)))
                    .PostFilter(q => q
                        .QueryString(queryDescriptor => queryDescriptor
                           .Query($"*{searchString}*")
                           .Fields(fs => fs
                           .Field(p => p.experience, 10)
                           .Field(p => p.IndustryType, 5)
                           .Field(p => p.SubIndustryType, 3)))
                        )
                    .PostFilter(q => q.Bool(bq => bq.Filter(filters))));

When i try to apply this i am not getting any result. My need is to search for company name from object where company name exist

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