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
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=retailonly works becauseelasticsearchwill break the query up intoq OR retail. You can target fields using regular lucene syntax i.etargetBusiness.industry:retail.In elasticsearch if your querystring is not bound to a field it will by default search in the
_allfield 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_allsupport 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_stringquery.Say if this is your query:
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
and then