Outsource parts in queries

So let's say I have the following code in C# using NEST:

    private ISearchResponse<Country> GetFilteredResultsByIds(ElasticClient client,
        Query query)
    {
        return client.Search<Country>(s => s
            .From(0)
            .Size(10)
            .Query(q => q
                .Nested(n => n
                    .Path(p => p.Customer)
                    .Query(q => q
                        .Term(t => t
                            .Field(f => f.Customer.CustomerId).Value(query.CustomerId)))
                ) && q
                .Nested(n => n
                    .Path(p => p.Person)
                    .Query(q => q
                        .Term(t => t
                            .Field(f => f.Person.ServiceId).Value(query.ServiceId))))));
    }

is it possible to outsource parts of the search query to external classes/parameters? For example the Customer and Person part to be able to reuse this in another query.

Take a look at search templates, where you only have to provide the parameters for your searches. See Search templates | Elasticsearch Guide [8.1] | Elastic

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