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 8808303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:35:21+00:00 2026-06-14T02:35:21+00:00

So I have successfully created my index of Package objects and a straight forward

  • 0

So I have successfully created my index of “Package” objects and a straight forward text query is working perfectly.

I’d love to know if / how i can use a partially populated object (of type “Package”) as the criteria for my search?

Packages looks something like:

var packages =  new List<Package> {
            new Package {
                Name = "Maverick",
                TargetBusiness = new Business {
                    Industry = "Retail",
                    BusinessType = BusinessType.Product,
                    LocationType = LocationType.Store
                },
                Description = "Standard package for retail shops"
            },
            new Package {
                Name = "Goose",
                TargetBusiness = new Business {
                    Industry = "Retail",
                    BusinessType = BusinessType.Product,
                    LocationType = LocationType.Online
                },
                Description = "Standard package for ecommerce shops"
            },
            new Package {
                Name = "Viper",
                TargetBusiness = new Business {
                    Industry = "Advertising",
                    BusinessType = BusinessType.Service,
                    LocationType = LocationType.Office
                },
                Description = "Standard package test retail"
            }
        }

query currently looks something like:

var result = client.Search<Package>(x => x.Query(q => q.QueryString(qs => qs.Query("q=retail"))));

But id like to have something like:

var result = client.Search<Package>(x => x.Query(q => q.Object(new Package{...etc ...})));

I hope I’m making sense 😀
Thanks in advance

  • 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-14T02:35:22+00:00Added an answer on June 14, 2026 at 2:35 am
    var result = client.Search<Package>(x => x.Query(q => q.Object(new Package{...etc ...})));
    

    Can never work because Nest cannot infer what type of query to use for each property on your object, (i.e term, prefix, wildcard, query_string, etc etc etc).

    In your example q=retail only works because elasticsearch will break the query up into q OR retail. You can target fields using regular lucene syntax i.e targetBusiness.industry:retail.

    In elasticsearch if your querystring is not bound to a field it will by default search in the _all field which will have all the terms for all the properties of an object. Which is why if you really have a lot of data turning off _all support is usually a really good idea.

    Nest doesn’t currently have such a functionality where it can take a partially filled object and translate it into an elasticsearch query_string query.

    Say if this is your query:

    client.Search<Package>(s=>s
        .From(0)
        .Size(10)
        .Filter(f=>
            f.Term(p=>p.TargetBusiness.Industry, "Advertising")
            && f.Exists(p=>p.Name)
        )
        .Query(q=>
           q.QueryString(qs=>qs
               .Query("ecommerce")
               .Operator(Operator.and)
           )
        )
    )
    

    In the above example you’ll have to create your own method that gives all the terms to search for in the query string query based on your package.

    i.e

    public string MyPackageQueryString(Package package) 
    {
        var myTerms = List<string>();
        myTerms.Add(package.Name);
        if (package.TargetBusiness != null)
        {
            myTerms.Add(package.Industry)
            ....
        }
        ...
        return string.Join(" ", myTerms.Where(t=>!string.IsNullOrWhiteSpace(t)));
    }
    

    and then

    client.Search<Package>(s=>s
        .From(0)
        .Size(10)
        .Filter(f=>
            f.Term(p=>p.TargetBusiness.Industry, "Advertising")
            && f.Exists(p=>p.Name)
        )
        .Query(q=>
           q.QueryString(qs=>qs
               .Query(this.MyPackageQueryString(package))
               .Operator(Operator.or)
           )
        )
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have successfully created a QListWidget that displays 2 lines of text for each
I have recently just started working with Lucene (specifically, Lucene.Net) and have successfully created
I have successfully created a db in Matlab using the Visual Query builder (database
I have successfully created a feature in sharepoint that modifies the existing edit dialog
I have successfully created a custom Facebook open graph action, and have been able
i have successfully created distribution profiles and installed on my xcode organiser, but this
I have successfully created an application which is workable on the >3.0 devices. However,
I have successfully created an app that reads from a bundled .plist file and
I have created a REST web service and successfully used it with a client.
I have created a script on mac OS X and it successfully sent an

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.