Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8919781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:06:37+00:00 2026-06-15T06:06:37+00:00

I have an interesting challenge, which I think there is an easy answer to.

  • 0

I have an interesting challenge, which I think there is an easy answer to.

I know that NEST filters work correctly when syntactically you do something like this:

var andFilter = FilterFactory.AndFilter(
                    FilterFactory.TermFilter("name.first", "shay1"),
                    FilterFactory.TermFilter("name.first", "shay4")
                );

My base services should allow an the caller to pass in some sort of enumerable list of items to filter.

I’d basically like to be able programmatically achieve something like this (filters is passed into the method):

var andFilter = new FilterDescriptor();
foreach (var filter in filters) 
{
     andFilter = filter concatenated to andFilter
}

In other words if I passed in an array of { {“first.name”, “joe”}, {“first.name”, “jim”}, {“first.name”, “frank”}} I would like to produce the equivalent of

var andFilter = FilterFactory.AndFilter(
                    FilterFactory.TermFilter("name.first", "joe"), 
                    FilterFactory.TermFilter("name.first", "joe"),
                    FilterFactory.TermFilter("name.first", "frank")
                );
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:06:37+00:00Added an answer on June 15, 2026 at 6:06 am

    Using the lambda based DSL you can do the following:

    var termsFilters = from tp in termParameters
                       let field = ToCamelCaseNestedNames(tp.SearchField)
                       let terms = tp.SearchValues
                       select Filter.Terms(field, terms);
    
    var prefixFilters = from tp in prefixParameters
                        let field = ToCamelCaseNestedNames(tp.SearchField)
                        let prefix = tp.SearchValues.FirstOrDefault().ToLowerInvariant()
                        select Filter.Prefix(field, prefix);
    
    var search = client.Search(s => s
        .From(0)
        .Size(20)
        .Filter(f => f.And(termsFilters.Concat(prefixFilters).ToArray()))
    );
    

    Which i think reads a bit better 🙂

    Nest now also supports conditionless queries so if any tp.SearchValues is null, empty or all empty strings or tp.SearchField is null or empty it will skip that terms/prefix query.

    You can revert this behavior easily though:

    var search = client.Search(s => s
        .Strict()
        .From(0)
        .Size(20)
        .Filter(f => f.And(termsFilters.Concat(prefixFilters).ToArray()))
    );
    

    which will throw a DslException if an empty query is generated.

    As a last note client.Search() will return a QueryResult<dynamic> if you can strongly type your documents so can do a client.Search<MyDocument>().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an interesting dilemma to which, I hope, someone may have an answer.
I have an interesting challenge that I'm wondering if anyone here can give me
We have an interesting challenge. We have to control access to data that reside
I have an interesting scenario. I have a task model which has a task
I have an interesting situation that EMF forced me into: abstract class AbstractDog{ ...
We have an interesting problem with WCF binding and streaming transfer mode that we
I have an interesting SQL problem that I need help with. Here is the
I have stumbled on an interesting challenge regarding active record associations: I have an
Okay, this is quite an interesting challenge I have got myself into. My RegEx
I have an interesting bit of logic that I can't seem to get my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.