.net - Use LINQ to Process Elastic Search Results -



.net - Use LINQ to Process Elastic Search Results -

what most-efficient method using linq process elasticsearch results?

i came across json.net's jobject class.

is json returned elasticsearch structured in fashion lends proper linq queries via jobject class?

this finish solution on how utilize linq process json query-results elasticsearch engine.

connection library - plainelastic.net

first off, using plainelastic.net 1 single purpose: connecting elasticsearch server. library lean , contains concise get, post, , set functions. comes play below client connection object. result.tostring() provides json response elasticsearch server. slap dll bin , add together reference.

json processor - json.net

i using great feature of newtonsoft json.net facilitate linq queries. library has class jobject provides nestable, queryable construction execute linq against. see line below grab hitcount see how nice grab individual value, and, of course, check out linq query see how query against it. remember, data-structure result of parsing json string. slap dll bin , add together reference.

performing query against elastic search 'execute search dim client = new elasticconnection("localhost", 9200) dim result = client.post("myindex/mytype/_search", elastic_query) 'elastic_query = well-formatted elasticsearch query (json string)' dim j jobject = jobject.parse(result.tostring()) 'how many results located? dim hitcount = cint(j("hits")("total")) 'what maximum score? maybe want know normalizing scores 0-100. ' - create sure have hits first ' - also, create sure scoring turned on. might turned off if alternate sort method used in query if hitcount > 0 andalso j("hits")("max_score").type <> jtokentype.null maxscore = cdbl(j("hits")("max_score")) processing results linq

now, utilize linq provide beautiful anonymous object binding gridviews, datalists, repeaters, etc. intentionally providing illustration of non-trivial linq query. illustration gets nested info (stores, categories)

dim searchresults = _ (from x in j("hits")("hits") select score = cdec(if(x("_score").type = jtokentype.null, 0, x("_score"))), boost = cdbl(x("_source")("_boost")), institutionid = cint(x("_source")("institutionid")), name = cstr(x("_source")("name")), stores = (from s in x("_source")("stores") select cint(s("storeid"))).tolist(), categories = (from z in x("_source")("categories") select catid = cint(z("catid")), catname = cstr(z("catname")), institutionid = cint(x("_source")("institutionid"))).tolist() order score descending, boost descending )

now, can bind repeater, datalist, or gridview

myrepeater.datasource = searchresults myrepeater.databind()

.net vb.net linq elasticsearch

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -