No. You're missing the point that [subquery] is called when assembling the return packet, which consists of only the top N docs from your query against the static collection, _not_ as part of the search which it would have to be to do what you want.
To sort the complete result set, you have to ask for every document that matches "does the value here match rank it in the top N (where rows=N)? That would be enormously expensive if each and every doc that matched needed to make a sub-query. bq: since we have combined them together in the result You have not really done this. This is not like a SQL query, all you're combining is the stored fields from the "rows=" parameter, _not_ the complete result set. You might be able to do something with streaming. You might be able to do something with updateable docValues. But you can't do what you're asking the way you're trying to. Best, Erick On Mon, Nov 27, 2017 at 8:20 PM, Jinyi Lu <jin...@vmware.com> wrote: > Thank you for the reply! > > In terms of sort, I am wondering is it possible to sort the docs from my > static collection based on the corresponding counts in the dynamic > collection, since we have combined them together in the result. > Something like: > sort=max(status.cnt) asc > > Or is it possible to add a multiValued pseudo field "cnts" using a subquery > for every static doc in the result, and then sort the static doc by the > pseudo field? > Something like: > fl=*,cnts:[subquery]&cnts.q=={!term f=object_id > v=$row.id}&cnts.fl=cnt&sort=max(cnts) asc > > Thanks, > Jinyi > > On 11/27/17, 6:04 PM, "Erick Erickson" <erickerick...@gmail.com> wrote: > > I'm not quite sure what "sort the results" means here. The [subquery] > bit just adds a field to the output of the top N. So what you'd be > doing here is just getting the top 10 (if &rows=10) from your static > collection, then adding the counts to them from the "dynamic" > collection. So the sort here you're asking for would not be ordered by > actual counts in the dynamic collection, the 11th document may have a > count much greater than anything in the results list. > > If anything you need to turn it around and query your dynamic > collection and add [subquery] to the top N from your static > collection. > > Best, > Erick > > Best, > Erick > > On Mon, Nov 27, 2017 at 1:39 PM, Jinyi Lu <jin...@vmware.com> wrote: > > Hi all, > > > > I have a question about how to sort results based on the fields in the > subquery. It’s exactly same as this question posted on the stackoverflow > https://urldefense.proofpoint.com/v2/url?u=https-3A__stackoverflow.com_questions_47127478_solr-2Dhow-2Dto-2Dsort-2Dbased-2Don-2Dsubquery&d=DwIFaQ&c=uilaK90D4TOVoH58JNXRgQ&r=9_rAkkO7SJ7HHMsaZXKAFNMoKpKiTfF8Eho2F9ygvjQ&m=oA6uB1I6AEAC64URTsslH7aCCfxu34orl2K5xnzvKTQ&s=bVCaDnDL8m0xXsxi8vhCrgiUFwYVyfICucICSVrnZFk&e= > but no answer yet. > > > > Basically, I have two collections: > > > > 1. Static data like the information about the objects. > > { > > "id": "a", > > "type": "type1" > > } > > > > 1. Status about the objects in the previous collection which will be > frequently updated. > > { > > "object_id": "a", > > "cnt": 1 > > } > > > > By using queries like q=id:*&fl=*,status:[subquery]&status.q= > status.q={!term f=object_id v=$row.id}, I am able to combine two collections > together and the response is something like: > > [{ > > "id": "a", > > "type": "type1" > > "status":{"numFound":1, "start":0, "docs":[ > > { > > "object_id": "a", > > "cnt": 1 > > }] > > } > > }, > > …] > > > > But is there a way to sort the results based on the fields in the > subquery, like "cnt" in this case? Any ideas are appreciated! > > > > Thanks! > > Jinyi > >