Our index consists of a text field for notes. The notes can be tied to multiple entity types in our system such as a job, worker, company, etc. So, I need to somehow construct the search query based on what type of entity the user wants to restrict the notes type to. So, for example, if a user is looking for all notes with a specific keyword that are also company notes, I want to do something like below (I think).
var searchResponse = client.Search<NotesAll>(s => s .From(viewModel.Page * retval.PageSize) .Size(retval.PageSize) .Query(q => q .Match(m => m .Field(f => f.Notes) .Query(viewModel.Keyword.ToLower()) ) ) .Query(q => q.Exists(y => y.Field(x => x.Company))) .Sort(x => x.Descending(y => y.LastModifiedDate)) );
Trying to match the keyword in the notes where also, the company field is not null.
The problem I have is that I have to create the second Query for Exists based on what type of search they're running and I'm not sure how to do that without having a bunch of case statements. I was hoping with NEST I would have a search object that I could add additional criteria to. Maybe it does and I'm just not seeing how. Any thoughts? Thanks!