Salvia
Salvia

Reputation: 182

Apache Solr - Count of subquery as a superquery parameter

I'm having a little trouble trying to make a query in Solr. The problem is: I must be able retrieve documents that have the same value for a specified field, but they should only be retrieved if this value appeared more than X times for a specified user. In pseudosql it would be something like:

select user_id from documents
where my_field="my_value"
and
(select count(*) from documents where my_field="my_value" and user_id=super.user_id) > X

I Know that solr return a 'numFound' for each query you make, but I dont know how to retrieve this value in a subquery.

My Solr is organized in a way that a user is a document, and the properties of the user (such as name, age, etc) are grouped in another document with a 'root_id' field. So lets suppose the following query that gets all the root documents whose children have the prefix "some_prefix".

is_root:true AND _query_:"{!join from=root_id to=id}requests_prefix:\"some_prefix\""

Now, how can I get the root documents (users in some sense) that have more than X children matching 'requests_prefix:"some_prefix"' or any other condition? Is it possible?

P.S. It must be done in a single query, fields can be added at will, but the root/children structure should be preserved (preferentially).

Upvotes: 2

Views: 664

Answers (1)

Salvia
Salvia

Reputation: 182

As it turns out, Solr didn't match my needs and I ended up using ElasticSearch with its nativa parent-child mapping.

Upvotes: 2

Related Questions