You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@solr.apache.org by jay harkhani <ja...@hotmail.com> on 2021/05/24 15:12:32 UTC

Unique function not working for Solr (Ver: 6.0.1) nested facets

Hello,

In our collection there are some documents which have same value for different fields while other have different values. i.e. For document1: status="xyz" and poi="draft", For document2: status="xyz" and poi="draft", For document3: status="abc" and poi="information". We have created facet query to search through all documents to get distinct count for documents where status="xyz" with poi="draft". Following query used to get count from solr:

json.facet={workspace:{type:terms,field:workspace,limit:100, facet:{x:"unique(doc_id)"},facet:{status:{type:terms,field:status,limit:-1, facet:{x:"unique(doc_id)"},facet:{poi:{type:terms,field:poi,limit:-1,facet:{x:"unique(doc_id)"}}}}}}}

Response from solr as below:

"facets":{
    "count":4,
    "workspace":{
      "buckets":[{
          "val":161650,
          "count":4,
          "status":{
            "buckets":[{
                "val":3,
                "count":4,
                "poi":{
                  "buckets":[{
                      "val":0,
                      "count":4,
                      "x":2}]}}]}}]}}}

Here we get unique document count for poi only. It not works for workspace and status field.

How can we apply unique function with multiple level of facet to get unique count in each level.

Regards,
Jay Harkhani.

Re: Unique function not working for Solr (Ver: 6.0.1) nested facets

Posted by Michael Gibney <mi...@michaelgibney.net>.
I think your facet request syntax is wrong (you have duplicate "facet"
keys for all but the "leaf" (poi) facet, which is why you see the
"leaf"/poi facet working, but not the others). I wonder whether this
should throw a 400 error? In any case could you see whether the
following works as expected?:

workspace:{
  type:terms,
  field:workspace,
  limit:100,
  facet:{
    x:"unique(doc_id)",
    status:{
      type:terms,
      field:status,
      limit:-1,
      facet:{
        x:"unique(doc_id)",
        poi:{
          type:terms,
          field:poi,
          limit:-1,
          facet:{x:"unique(doc_id)"}
        }
      }
    }
  }
}

On Mon, May 24, 2021 at 11:12 AM jay harkhani <ja...@hotmail.com> wrote:
>
> Hello,
>
> In our collection there are some documents which have same value for different fields while other have different values. i.e. For document1: status="xyz" and poi="draft", For document2: status="xyz" and poi="draft", For document3: status="abc" and poi="information". We have created facet query to search through all documents to get distinct count for documents where status="xyz" with poi="draft". Following query used to get count from solr:
>
> json.facet={workspace:{type:terms,field:workspace,limit:100, facet:{x:"unique(doc_id)"},facet:{status:{type:terms,field:status,limit:-1, facet:{x:"unique(doc_id)"},facet:{poi:{type:terms,field:poi,limit:-1,facet:{x:"unique(doc_id)"}}}}}}}
>
> Response from solr as below:
>
> "facets":{
>     "count":4,
>     "workspace":{
>       "buckets":[{
>           "val":161650,
>           "count":4,
>           "status":{
>             "buckets":[{
>                 "val":3,
>                 "count":4,
>                 "poi":{
>                   "buckets":[{
>                       "val":0,
>                       "count":4,
>                       "x":2}]}}]}}]}}}
>
> Here we get unique document count for poi only. It not works for workspace and status field.
>
> How can we apply unique function with multiple level of facet to get unique count in each level.
>
> Regards,
> Jay Harkhani.