You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Arturas Mazeika <ma...@gmail.com> on 2020/12/03 08:47:26 UTC

nested facets of query and terms type in JSON format

Hi Solr Team,

I am trying to check how I can formulate facet queries using JSON format. I
can successfully formulate query, range, term queries, as well as nested
term queries. How can I formulate a nested facet query involving "query" as
well as "range" formulations? The following does not work:


GET http://localhost:5555/solr/db/query HTTP/1.1
content-type: application/json

{
    "query"  : "*:*",
    "limit"  : 0,
    "facet": {
        "a1": { "query":  "cfname2:1" },
        "a2": { "query":  "cfname2:2" },
        "a3": { "field":  "cfname2", "type":"terms", "prefix":"3" },
        "a4": { "query":  "cfname2:4" },
        "a5": { "query":  "cfname2:5" },
        "a6": { "query":  "cfname2:6" },

        "tt": {
            "t_buckets": {
                "type":  "range",
                "field": "t",
                "sort": { "t": "asc" },
                "start": "2018-05-02T17:00:00.000Z",
                "end":   "2020-11-16T21:00:00.000Z",
                "gap":   "+1HOUR"
            }
        }
    }
}

Single (not nested facets separately on individual queries as well as for
range) work in flying colors.

Cheers,
Arturas

Re: nested facets of query and terms type in JSON format

Posted by Arturas Mazeika <ma...@gmail.com>.
Hi Jason,

Thanks a lot for the post. Indeed the web page you are referring to has
some very nice examples. Well done.

Cheers,
Arturas

Increasing the number of threads (through the url or params section) is
unsuccessful so far. Maybe solr takes it only as a hint.

On Thu, Dec 10, 2020 at 8:01 PM Jason Gerlowski <ge...@gmail.com>
wrote:

> Hey Arturas,
>
> Can't help you with the secrets of Michael's inspiration (though I'm
> also curious :-p).  And I'm not sure if there's any equivalent of
> facet.threads for JSON Faceting.  You're on your own there
> unfortunately.
>
> But you (or other readers) might find this "Query Facet" example handy
> - it uses the "type": "query" syntax that MIchael mentioned. [1]
>
> [1]
> https://lucene.apache.org/solr/guide/8_5/json-facet-api.html#query-facet
>
> Best,
> Jason
>
> On Thu, Dec 3, 2020 at 5:49 PM Arturas Mazeika <ma...@gmail.com> wrote:
> >
> > Hi Michael,
> >
> > I wish I were able to do a percent of what you are doing. Where does your
> > inspiration come from? It is not from the manuals, cause I've checked
> > those. How do you come up with this piece of art? Did you check this from
> > the source code? Which lines revealed these secrets? I am eternally
> > grateful for your help!
> >
> > Michael, maybe you happen to know how I can plugin in facet.threads
> > parameter in that JSON body below, so the query uses more threads to
> > compute the answer? I am dying out of curiosity.
> >
> > Cheers,
> > Arturas
> >
> > On Thu, Dec 3, 2020 at 7:59 PM Michael Gibney <michael@michaelgibney.net
> >
> > wrote:
> >
> > > I think the first "error" case in your set of examples above is
> closest to
> > > being correct. For "query" facet type, I think you want to explicitly
> > > specify `"type":"query"`, and specify the query itself in the `"q"`
> param,
> > > i.e.:
> > > {
> > >     "query"  : "*:*",
> > >     "limit"  : 0,
> > >
> > >     "facet": {
> > >         "aip": {
> > >             "type":  "query",
> > >             "q":  "cfname2:aip",
> > >             "facet": {
> > >                 "t_buckets": {
> > >                     "type":  "range",
> > >                     "field": "t",
> > >                     "sort": { "t": "asc" },
> > >                     "start": "2018-05-02T17:00:00.000Z",
> > >                     "end":   "2020-11-16T21:00:00.000Z",
> > >                     "gap":   "+1HOUR"
> > >                     "limit": 1
> > >                 }
> > >             }
> > >         }
> > >     }
> > > }
> > >
> > > On Thu, Dec 3, 2020 at 12:59 PM Arturas Mazeika <ma...@gmail.com>
> wrote:
> > >
> > > > Hi Michael,
> > > >
> > > > Thanks for helping me to figure this out.
> > > >
> > > > If I fire:
> > > >
> > > > {
> > > >     "query"  : "*:*",
> > > >     "limit"  : 0,
> > > >
> > > >     "facet": {
> > > >         "aip": { "query":  "cfname2:aip", }
> > > >
> > > >     }
> > > > }
> > > >
> > > > I get
> > > >
> > > > "response": { "numFound": 20560849, "start": 0, "numFoundExact":
> true,
> > > > "docs": [] }, "facets": { "count": 20560849, "aip": { "count": 2307
> } } }
> > > >
> > > > (works). If I fire
> > > >
> > > >
> > > > {
> > > >     "query"  : "*:*",
> > > >     "limit"  : 0,
> > > >
> > > >     "facet": {
> > > >         "t_buckets": {
> > > >             "type":  "range",
> > > >             "field": "t",
> > > >             "sort": { "t": "asc" },
> > > >             "start": "2018-05-02T17:00:00.000Z",
> > > >             "end":   "2020-11-16T21:00:00.000Z",
> > > >             "gap":   "+1HOUR"
> > > >             "limit": 1
> > > >         }
> > > >     }
> > > > }
> > > >
> > > > I get
> > > >
> > > > "response": { "numFound": 20560849, "start": 0, "numFoundExact":
> true,
> > > > "docs": [] }, "facets": { "count": 20560849, "t_buckets": {
> "buckets": [
> > > {
> > > > "val": "2018-05-02T17:00:00Z", "count": 150 },
> > > >
> > > > (works). If I fire:
> > > >
> > > > {
> > > >     "query"  : "*:*",
> > > >     "limit"  : 0,
> > > >
> > > >     "facet": {
> > > >         "aip": { "query":  "cfname2:aip",
> > > >
> > > >             "facet": {
> > > >                 "t_buckets": {
> > > >                     "type":  "range",
> > > >                     "field": "t",
> > > >                     "sort": { "t": "asc" },
> > > >                     "start": "2018-05-02T17:00:00.000Z",
> > > >                     "end":   "2020-11-16T21:00:00.000Z",
> > > >                     "gap":   "+1HOUR"
> > > >                     "limit": 1
> > > >                 }
> > > >             }
> > > >         }
> > > >     }
> > > > }
> > > >
> > > > I get
> > > >
> > > > "error": { "metadata": [ "error-class",
> > > > "org.apache.solr.common.SolrException", "root-error-class",
> > > > "org.apache.solr.common.SolrException" ], "msg": "expected facet/stat
> > > type
> > > > name, like {type:range, field:price, ...} but got null ,
> path=/facet",
> > > > "code": 400 } }
> > > >
> > > > If I fire
> > > >
> > > > {
> > > >     "query"  : "*:*",
> > > >     "limit"  : 0,
> > > >
> > > >     "facet": {
> > > >         "aip": { "query":  "cfname2:aip",
> > > >
> > > >             "facet": {
> > > >                 "type":  "range",
> > > >                 "field": "t",
> > > >                 "sort": { "t": "asc" },
> > > >                 "start": "2018-05-02T17:00:00.000Z",
> > > >                 "end":   "2020-11-16T21:00:00.000Z",
> > > >                 "gap":   "+1HOUR"
> > > >                 "limit": 1
> > > >             }
> > > >         }
> > > >     }
> > > > }
> > > >
> > > > I get
> > > >
> > > > "error": { "metadata": [ "error-class",
> > > > "org.apache.solr.common.SolrException", "root-error-class",
> > > > "org.apache.solr.common.SolrException" ], "msg": "expected facet/stat
> > > type
> > > > name, like {type:range, field:price, ...} but got null ,
> path=/facet",
> > > > "code": 400 } }
> > > >
> > > > What else can I try out?
> > > >
> > > > Cheers,
> > > > Arturas
> > > >
> > > > On Thu, Dec 3, 2020 at 3:55 PM Michael Gibney <
> michael@michaelgibney.net
> > > >
> > > > wrote:
> > > >
> > > > > Arturas,
> > > > > I think your syntax is wrong for the range subfacet? -- the
> > > configuration
> > > > > of the range facet should be directly under the `tt` key, rather
> than
> > > > > nested under `t_buckets` in the request. (The response introduces a
> > > > > "buckets" attribute that is not part of the request syntax).
> > > > > Michael
> > > > >
> > > > > On Thu, Dec 3, 2020 at 3:47 AM Arturas Mazeika <ma...@gmail.com>
> > > > wrote:
> > > > >
> > > > > > Hi Solr Team,
> > > > > >
> > > > > > I am trying to check how I can formulate facet queries using JSON
> > > > > format. I
> > > > > > can successfully formulate query, range, term queries, as well as
> > > > nested
> > > > > > term queries. How can I formulate a nested facet query involving
> > > > "query"
> > > > > as
> > > > > > well as "range" formulations? The following does not work:
> > > > > >
> > > > > >
> > > > > > GET http://localhost:5555/solr/db/query HTTP/1.1
> > > > > > content-type: application/json
> > > > > >
> > > > > > {
> > > > > >     "query"  : "*:*",
> > > > > >     "limit"  : 0,
> > > > > >     "facet": {
> > > > > >         "a1": { "query":  "cfname2:1" },
> > > > > >         "a2": { "query":  "cfname2:2" },
> > > > > >         "a3": { "field":  "cfname2", "type":"terms",
> "prefix":"3" },
> > > > > >         "a4": { "query":  "cfname2:4" },
> > > > > >         "a5": { "query":  "cfname2:5" },
> > > > > >         "a6": { "query":  "cfname2:6" },
> > > > > >
> > > > > >         "tt": {
> > > > > >             "t_buckets": {
> > > > > >                 "type":  "range",
> > > > > >                 "field": "t",
> > > > > >                 "sort": { "t": "asc" },
> > > > > >                 "start": "2018-05-02T17:00:00.000Z",
> > > > > >                 "end":   "2020-11-16T21:00:00.000Z",
> > > > > >                 "gap":   "+1HOUR"
> > > > > >             }
> > > > > >         }
> > > > > >     }
> > > > > > }
> > > > > >
> > > > > > Single (not nested facets separately on individual queries as
> well as
> > > > for
> > > > > > range) work in flying colors.
> > > > > >
> > > > > > Cheers,
> > > > > > Arturas
> > > > > >
> > > > >
> > > >
> > >
>

Re: nested facets of query and terms type in JSON format

Posted by Jason Gerlowski <ge...@gmail.com>.
Hey Arturas,

Can't help you with the secrets of Michael's inspiration (though I'm
also curious :-p).  And I'm not sure if there's any equivalent of
facet.threads for JSON Faceting.  You're on your own there
unfortunately.

But you (or other readers) might find this "Query Facet" example handy
- it uses the "type": "query" syntax that MIchael mentioned. [1]

[1] https://lucene.apache.org/solr/guide/8_5/json-facet-api.html#query-facet

Best,
Jason

On Thu, Dec 3, 2020 at 5:49 PM Arturas Mazeika <ma...@gmail.com> wrote:
>
> Hi Michael,
>
> I wish I were able to do a percent of what you are doing. Where does your
> inspiration come from? It is not from the manuals, cause I've checked
> those. How do you come up with this piece of art? Did you check this from
> the source code? Which lines revealed these secrets? I am eternally
> grateful for your help!
>
> Michael, maybe you happen to know how I can plugin in facet.threads
> parameter in that JSON body below, so the query uses more threads to
> compute the answer? I am dying out of curiosity.
>
> Cheers,
> Arturas
>
> On Thu, Dec 3, 2020 at 7:59 PM Michael Gibney <mi...@michaelgibney.net>
> wrote:
>
> > I think the first "error" case in your set of examples above is closest to
> > being correct. For "query" facet type, I think you want to explicitly
> > specify `"type":"query"`, and specify the query itself in the `"q"` param,
> > i.e.:
> > {
> >     "query"  : "*:*",
> >     "limit"  : 0,
> >
> >     "facet": {
> >         "aip": {
> >             "type":  "query",
> >             "q":  "cfname2:aip",
> >             "facet": {
> >                 "t_buckets": {
> >                     "type":  "range",
> >                     "field": "t",
> >                     "sort": { "t": "asc" },
> >                     "start": "2018-05-02T17:00:00.000Z",
> >                     "end":   "2020-11-16T21:00:00.000Z",
> >                     "gap":   "+1HOUR"
> >                     "limit": 1
> >                 }
> >             }
> >         }
> >     }
> > }
> >
> > On Thu, Dec 3, 2020 at 12:59 PM Arturas Mazeika <ma...@gmail.com> wrote:
> >
> > > Hi Michael,
> > >
> > > Thanks for helping me to figure this out.
> > >
> > > If I fire:
> > >
> > > {
> > >     "query"  : "*:*",
> > >     "limit"  : 0,
> > >
> > >     "facet": {
> > >         "aip": { "query":  "cfname2:aip", }
> > >
> > >     }
> > > }
> > >
> > > I get
> > >
> > > "response": { "numFound": 20560849, "start": 0, "numFoundExact": true,
> > > "docs": [] }, "facets": { "count": 20560849, "aip": { "count": 2307 } } }
> > >
> > > (works). If I fire
> > >
> > >
> > > {
> > >     "query"  : "*:*",
> > >     "limit"  : 0,
> > >
> > >     "facet": {
> > >         "t_buckets": {
> > >             "type":  "range",
> > >             "field": "t",
> > >             "sort": { "t": "asc" },
> > >             "start": "2018-05-02T17:00:00.000Z",
> > >             "end":   "2020-11-16T21:00:00.000Z",
> > >             "gap":   "+1HOUR"
> > >             "limit": 1
> > >         }
> > >     }
> > > }
> > >
> > > I get
> > >
> > > "response": { "numFound": 20560849, "start": 0, "numFoundExact": true,
> > > "docs": [] }, "facets": { "count": 20560849, "t_buckets": { "buckets": [
> > {
> > > "val": "2018-05-02T17:00:00Z", "count": 150 },
> > >
> > > (works). If I fire:
> > >
> > > {
> > >     "query"  : "*:*",
> > >     "limit"  : 0,
> > >
> > >     "facet": {
> > >         "aip": { "query":  "cfname2:aip",
> > >
> > >             "facet": {
> > >                 "t_buckets": {
> > >                     "type":  "range",
> > >                     "field": "t",
> > >                     "sort": { "t": "asc" },
> > >                     "start": "2018-05-02T17:00:00.000Z",
> > >                     "end":   "2020-11-16T21:00:00.000Z",
> > >                     "gap":   "+1HOUR"
> > >                     "limit": 1
> > >                 }
> > >             }
> > >         }
> > >     }
> > > }
> > >
> > > I get
> > >
> > > "error": { "metadata": [ "error-class",
> > > "org.apache.solr.common.SolrException", "root-error-class",
> > > "org.apache.solr.common.SolrException" ], "msg": "expected facet/stat
> > type
> > > name, like {type:range, field:price, ...} but got null , path=/facet",
> > > "code": 400 } }
> > >
> > > If I fire
> > >
> > > {
> > >     "query"  : "*:*",
> > >     "limit"  : 0,
> > >
> > >     "facet": {
> > >         "aip": { "query":  "cfname2:aip",
> > >
> > >             "facet": {
> > >                 "type":  "range",
> > >                 "field": "t",
> > >                 "sort": { "t": "asc" },
> > >                 "start": "2018-05-02T17:00:00.000Z",
> > >                 "end":   "2020-11-16T21:00:00.000Z",
> > >                 "gap":   "+1HOUR"
> > >                 "limit": 1
> > >             }
> > >         }
> > >     }
> > > }
> > >
> > > I get
> > >
> > > "error": { "metadata": [ "error-class",
> > > "org.apache.solr.common.SolrException", "root-error-class",
> > > "org.apache.solr.common.SolrException" ], "msg": "expected facet/stat
> > type
> > > name, like {type:range, field:price, ...} but got null , path=/facet",
> > > "code": 400 } }
> > >
> > > What else can I try out?
> > >
> > > Cheers,
> > > Arturas
> > >
> > > On Thu, Dec 3, 2020 at 3:55 PM Michael Gibney <michael@michaelgibney.net
> > >
> > > wrote:
> > >
> > > > Arturas,
> > > > I think your syntax is wrong for the range subfacet? -- the
> > configuration
> > > > of the range facet should be directly under the `tt` key, rather than
> > > > nested under `t_buckets` in the request. (The response introduces a
> > > > "buckets" attribute that is not part of the request syntax).
> > > > Michael
> > > >
> > > > On Thu, Dec 3, 2020 at 3:47 AM Arturas Mazeika <ma...@gmail.com>
> > > wrote:
> > > >
> > > > > Hi Solr Team,
> > > > >
> > > > > I am trying to check how I can formulate facet queries using JSON
> > > > format. I
> > > > > can successfully formulate query, range, term queries, as well as
> > > nested
> > > > > term queries. How can I formulate a nested facet query involving
> > > "query"
> > > > as
> > > > > well as "range" formulations? The following does not work:
> > > > >
> > > > >
> > > > > GET http://localhost:5555/solr/db/query HTTP/1.1
> > > > > content-type: application/json
> > > > >
> > > > > {
> > > > >     "query"  : "*:*",
> > > > >     "limit"  : 0,
> > > > >     "facet": {
> > > > >         "a1": { "query":  "cfname2:1" },
> > > > >         "a2": { "query":  "cfname2:2" },
> > > > >         "a3": { "field":  "cfname2", "type":"terms", "prefix":"3" },
> > > > >         "a4": { "query":  "cfname2:4" },
> > > > >         "a5": { "query":  "cfname2:5" },
> > > > >         "a6": { "query":  "cfname2:6" },
> > > > >
> > > > >         "tt": {
> > > > >             "t_buckets": {
> > > > >                 "type":  "range",
> > > > >                 "field": "t",
> > > > >                 "sort": { "t": "asc" },
> > > > >                 "start": "2018-05-02T17:00:00.000Z",
> > > > >                 "end":   "2020-11-16T21:00:00.000Z",
> > > > >                 "gap":   "+1HOUR"
> > > > >             }
> > > > >         }
> > > > >     }
> > > > > }
> > > > >
> > > > > Single (not nested facets separately on individual queries as well as
> > > for
> > > > > range) work in flying colors.
> > > > >
> > > > > Cheers,
> > > > > Arturas
> > > > >
> > > >
> > >
> >

Re: nested facets of query and terms type in JSON format

Posted by Arturas Mazeika <ma...@gmail.com>.
Hi Michael,

I wish I were able to do a percent of what you are doing. Where does your
inspiration come from? It is not from the manuals, cause I've checked
those. How do you come up with this piece of art? Did you check this from
the source code? Which lines revealed these secrets? I am eternally
grateful for your help!

Michael, maybe you happen to know how I can plugin in facet.threads
parameter in that JSON body below, so the query uses more threads to
compute the answer? I am dying out of curiosity.

Cheers,
Arturas

On Thu, Dec 3, 2020 at 7:59 PM Michael Gibney <mi...@michaelgibney.net>
wrote:

> I think the first "error" case in your set of examples above is closest to
> being correct. For "query" facet type, I think you want to explicitly
> specify `"type":"query"`, and specify the query itself in the `"q"` param,
> i.e.:
> {
>     "query"  : "*:*",
>     "limit"  : 0,
>
>     "facet": {
>         "aip": {
>             "type":  "query",
>             "q":  "cfname2:aip",
>             "facet": {
>                 "t_buckets": {
>                     "type":  "range",
>                     "field": "t",
>                     "sort": { "t": "asc" },
>                     "start": "2018-05-02T17:00:00.000Z",
>                     "end":   "2020-11-16T21:00:00.000Z",
>                     "gap":   "+1HOUR"
>                     "limit": 1
>                 }
>             }
>         }
>     }
> }
>
> On Thu, Dec 3, 2020 at 12:59 PM Arturas Mazeika <ma...@gmail.com> wrote:
>
> > Hi Michael,
> >
> > Thanks for helping me to figure this out.
> >
> > If I fire:
> >
> > {
> >     "query"  : "*:*",
> >     "limit"  : 0,
> >
> >     "facet": {
> >         "aip": { "query":  "cfname2:aip", }
> >
> >     }
> > }
> >
> > I get
> >
> > "response": { "numFound": 20560849, "start": 0, "numFoundExact": true,
> > "docs": [] }, "facets": { "count": 20560849, "aip": { "count": 2307 } } }
> >
> > (works). If I fire
> >
> >
> > {
> >     "query"  : "*:*",
> >     "limit"  : 0,
> >
> >     "facet": {
> >         "t_buckets": {
> >             "type":  "range",
> >             "field": "t",
> >             "sort": { "t": "asc" },
> >             "start": "2018-05-02T17:00:00.000Z",
> >             "end":   "2020-11-16T21:00:00.000Z",
> >             "gap":   "+1HOUR"
> >             "limit": 1
> >         }
> >     }
> > }
> >
> > I get
> >
> > "response": { "numFound": 20560849, "start": 0, "numFoundExact": true,
> > "docs": [] }, "facets": { "count": 20560849, "t_buckets": { "buckets": [
> {
> > "val": "2018-05-02T17:00:00Z", "count": 150 },
> >
> > (works). If I fire:
> >
> > {
> >     "query"  : "*:*",
> >     "limit"  : 0,
> >
> >     "facet": {
> >         "aip": { "query":  "cfname2:aip",
> >
> >             "facet": {
> >                 "t_buckets": {
> >                     "type":  "range",
> >                     "field": "t",
> >                     "sort": { "t": "asc" },
> >                     "start": "2018-05-02T17:00:00.000Z",
> >                     "end":   "2020-11-16T21:00:00.000Z",
> >                     "gap":   "+1HOUR"
> >                     "limit": 1
> >                 }
> >             }
> >         }
> >     }
> > }
> >
> > I get
> >
> > "error": { "metadata": [ "error-class",
> > "org.apache.solr.common.SolrException", "root-error-class",
> > "org.apache.solr.common.SolrException" ], "msg": "expected facet/stat
> type
> > name, like {type:range, field:price, ...} but got null , path=/facet",
> > "code": 400 } }
> >
> > If I fire
> >
> > {
> >     "query"  : "*:*",
> >     "limit"  : 0,
> >
> >     "facet": {
> >         "aip": { "query":  "cfname2:aip",
> >
> >             "facet": {
> >                 "type":  "range",
> >                 "field": "t",
> >                 "sort": { "t": "asc" },
> >                 "start": "2018-05-02T17:00:00.000Z",
> >                 "end":   "2020-11-16T21:00:00.000Z",
> >                 "gap":   "+1HOUR"
> >                 "limit": 1
> >             }
> >         }
> >     }
> > }
> >
> > I get
> >
> > "error": { "metadata": [ "error-class",
> > "org.apache.solr.common.SolrException", "root-error-class",
> > "org.apache.solr.common.SolrException" ], "msg": "expected facet/stat
> type
> > name, like {type:range, field:price, ...} but got null , path=/facet",
> > "code": 400 } }
> >
> > What else can I try out?
> >
> > Cheers,
> > Arturas
> >
> > On Thu, Dec 3, 2020 at 3:55 PM Michael Gibney <michael@michaelgibney.net
> >
> > wrote:
> >
> > > Arturas,
> > > I think your syntax is wrong for the range subfacet? -- the
> configuration
> > > of the range facet should be directly under the `tt` key, rather than
> > > nested under `t_buckets` in the request. (The response introduces a
> > > "buckets" attribute that is not part of the request syntax).
> > > Michael
> > >
> > > On Thu, Dec 3, 2020 at 3:47 AM Arturas Mazeika <ma...@gmail.com>
> > wrote:
> > >
> > > > Hi Solr Team,
> > > >
> > > > I am trying to check how I can formulate facet queries using JSON
> > > format. I
> > > > can successfully formulate query, range, term queries, as well as
> > nested
> > > > term queries. How can I formulate a nested facet query involving
> > "query"
> > > as
> > > > well as "range" formulations? The following does not work:
> > > >
> > > >
> > > > GET http://localhost:5555/solr/db/query HTTP/1.1
> > > > content-type: application/json
> > > >
> > > > {
> > > >     "query"  : "*:*",
> > > >     "limit"  : 0,
> > > >     "facet": {
> > > >         "a1": { "query":  "cfname2:1" },
> > > >         "a2": { "query":  "cfname2:2" },
> > > >         "a3": { "field":  "cfname2", "type":"terms", "prefix":"3" },
> > > >         "a4": { "query":  "cfname2:4" },
> > > >         "a5": { "query":  "cfname2:5" },
> > > >         "a6": { "query":  "cfname2:6" },
> > > >
> > > >         "tt": {
> > > >             "t_buckets": {
> > > >                 "type":  "range",
> > > >                 "field": "t",
> > > >                 "sort": { "t": "asc" },
> > > >                 "start": "2018-05-02T17:00:00.000Z",
> > > >                 "end":   "2020-11-16T21:00:00.000Z",
> > > >                 "gap":   "+1HOUR"
> > > >             }
> > > >         }
> > > >     }
> > > > }
> > > >
> > > > Single (not nested facets separately on individual queries as well as
> > for
> > > > range) work in flying colors.
> > > >
> > > > Cheers,
> > > > Arturas
> > > >
> > >
> >
>

Re: nested facets of query and terms type in JSON format

Posted by Michael Gibney <mi...@michaelgibney.net>.
I think the first "error" case in your set of examples above is closest to
being correct. For "query" facet type, I think you want to explicitly
specify `"type":"query"`, and specify the query itself in the `"q"` param,
i.e.:
{
    "query"  : "*:*",
    "limit"  : 0,

    "facet": {
        "aip": {
            "type":  "query",
            "q":  "cfname2:aip",
            "facet": {
                "t_buckets": {
                    "type":  "range",
                    "field": "t",
                    "sort": { "t": "asc" },
                    "start": "2018-05-02T17:00:00.000Z",
                    "end":   "2020-11-16T21:00:00.000Z",
                    "gap":   "+1HOUR"
                    "limit": 1
                }
            }
        }
    }
}

On Thu, Dec 3, 2020 at 12:59 PM Arturas Mazeika <ma...@gmail.com> wrote:

> Hi Michael,
>
> Thanks for helping me to figure this out.
>
> If I fire:
>
> {
>     "query"  : "*:*",
>     "limit"  : 0,
>
>     "facet": {
>         "aip": { "query":  "cfname2:aip", }
>
>     }
> }
>
> I get
>
> "response": { "numFound": 20560849, "start": 0, "numFoundExact": true,
> "docs": [] }, "facets": { "count": 20560849, "aip": { "count": 2307 } } }
>
> (works). If I fire
>
>
> {
>     "query"  : "*:*",
>     "limit"  : 0,
>
>     "facet": {
>         "t_buckets": {
>             "type":  "range",
>             "field": "t",
>             "sort": { "t": "asc" },
>             "start": "2018-05-02T17:00:00.000Z",
>             "end":   "2020-11-16T21:00:00.000Z",
>             "gap":   "+1HOUR"
>             "limit": 1
>         }
>     }
> }
>
> I get
>
> "response": { "numFound": 20560849, "start": 0, "numFoundExact": true,
> "docs": [] }, "facets": { "count": 20560849, "t_buckets": { "buckets": [ {
> "val": "2018-05-02T17:00:00Z", "count": 150 },
>
> (works). If I fire:
>
> {
>     "query"  : "*:*",
>     "limit"  : 0,
>
>     "facet": {
>         "aip": { "query":  "cfname2:aip",
>
>             "facet": {
>                 "t_buckets": {
>                     "type":  "range",
>                     "field": "t",
>                     "sort": { "t": "asc" },
>                     "start": "2018-05-02T17:00:00.000Z",
>                     "end":   "2020-11-16T21:00:00.000Z",
>                     "gap":   "+1HOUR"
>                     "limit": 1
>                 }
>             }
>         }
>     }
> }
>
> I get
>
> "error": { "metadata": [ "error-class",
> "org.apache.solr.common.SolrException", "root-error-class",
> "org.apache.solr.common.SolrException" ], "msg": "expected facet/stat type
> name, like {type:range, field:price, ...} but got null , path=/facet",
> "code": 400 } }
>
> If I fire
>
> {
>     "query"  : "*:*",
>     "limit"  : 0,
>
>     "facet": {
>         "aip": { "query":  "cfname2:aip",
>
>             "facet": {
>                 "type":  "range",
>                 "field": "t",
>                 "sort": { "t": "asc" },
>                 "start": "2018-05-02T17:00:00.000Z",
>                 "end":   "2020-11-16T21:00:00.000Z",
>                 "gap":   "+1HOUR"
>                 "limit": 1
>             }
>         }
>     }
> }
>
> I get
>
> "error": { "metadata": [ "error-class",
> "org.apache.solr.common.SolrException", "root-error-class",
> "org.apache.solr.common.SolrException" ], "msg": "expected facet/stat type
> name, like {type:range, field:price, ...} but got null , path=/facet",
> "code": 400 } }
>
> What else can I try out?
>
> Cheers,
> Arturas
>
> On Thu, Dec 3, 2020 at 3:55 PM Michael Gibney <mi...@michaelgibney.net>
> wrote:
>
> > Arturas,
> > I think your syntax is wrong for the range subfacet? -- the configuration
> > of the range facet should be directly under the `tt` key, rather than
> > nested under `t_buckets` in the request. (The response introduces a
> > "buckets" attribute that is not part of the request syntax).
> > Michael
> >
> > On Thu, Dec 3, 2020 at 3:47 AM Arturas Mazeika <ma...@gmail.com>
> wrote:
> >
> > > Hi Solr Team,
> > >
> > > I am trying to check how I can formulate facet queries using JSON
> > format. I
> > > can successfully formulate query, range, term queries, as well as
> nested
> > > term queries. How can I formulate a nested facet query involving
> "query"
> > as
> > > well as "range" formulations? The following does not work:
> > >
> > >
> > > GET http://localhost:5555/solr/db/query HTTP/1.1
> > > content-type: application/json
> > >
> > > {
> > >     "query"  : "*:*",
> > >     "limit"  : 0,
> > >     "facet": {
> > >         "a1": { "query":  "cfname2:1" },
> > >         "a2": { "query":  "cfname2:2" },
> > >         "a3": { "field":  "cfname2", "type":"terms", "prefix":"3" },
> > >         "a4": { "query":  "cfname2:4" },
> > >         "a5": { "query":  "cfname2:5" },
> > >         "a6": { "query":  "cfname2:6" },
> > >
> > >         "tt": {
> > >             "t_buckets": {
> > >                 "type":  "range",
> > >                 "field": "t",
> > >                 "sort": { "t": "asc" },
> > >                 "start": "2018-05-02T17:00:00.000Z",
> > >                 "end":   "2020-11-16T21:00:00.000Z",
> > >                 "gap":   "+1HOUR"
> > >             }
> > >         }
> > >     }
> > > }
> > >
> > > Single (not nested facets separately on individual queries as well as
> for
> > > range) work in flying colors.
> > >
> > > Cheers,
> > > Arturas
> > >
> >
>

Re: nested facets of query and terms type in JSON format

Posted by Arturas Mazeika <ma...@gmail.com>.
Hi Michael,

Thanks for helping me to figure this out.

If I fire:

{
    "query"  : "*:*",
    "limit"  : 0,

    "facet": {
        "aip": { "query":  "cfname2:aip", }

    }
}

I get

"response": { "numFound": 20560849, "start": 0, "numFoundExact": true,
"docs": [] }, "facets": { "count": 20560849, "aip": { "count": 2307 } } }

(works). If I fire


{
    "query"  : "*:*",
    "limit"  : 0,

    "facet": {
        "t_buckets": {
            "type":  "range",
            "field": "t",
            "sort": { "t": "asc" },
            "start": "2018-05-02T17:00:00.000Z",
            "end":   "2020-11-16T21:00:00.000Z",
            "gap":   "+1HOUR"
            "limit": 1
        }
    }
}

I get

"response": { "numFound": 20560849, "start": 0, "numFoundExact": true,
"docs": [] }, "facets": { "count": 20560849, "t_buckets": { "buckets": [ {
"val": "2018-05-02T17:00:00Z", "count": 150 },

(works). If I fire:

{
    "query"  : "*:*",
    "limit"  : 0,

    "facet": {
        "aip": { "query":  "cfname2:aip",

            "facet": {
                "t_buckets": {
                    "type":  "range",
                    "field": "t",
                    "sort": { "t": "asc" },
                    "start": "2018-05-02T17:00:00.000Z",
                    "end":   "2020-11-16T21:00:00.000Z",
                    "gap":   "+1HOUR"
                    "limit": 1
                }
            }
        }
    }
}

I get

"error": { "metadata": [ "error-class",
"org.apache.solr.common.SolrException", "root-error-class",
"org.apache.solr.common.SolrException" ], "msg": "expected facet/stat type
name, like {type:range, field:price, ...} but got null , path=/facet",
"code": 400 } }

If I fire

{
    "query"  : "*:*",
    "limit"  : 0,

    "facet": {
        "aip": { "query":  "cfname2:aip",

            "facet": {
                "type":  "range",
                "field": "t",
                "sort": { "t": "asc" },
                "start": "2018-05-02T17:00:00.000Z",
                "end":   "2020-11-16T21:00:00.000Z",
                "gap":   "+1HOUR"
                "limit": 1
            }
        }
    }
}

I get

"error": { "metadata": [ "error-class",
"org.apache.solr.common.SolrException", "root-error-class",
"org.apache.solr.common.SolrException" ], "msg": "expected facet/stat type
name, like {type:range, field:price, ...} but got null , path=/facet",
"code": 400 } }

What else can I try out?

Cheers,
Arturas

On Thu, Dec 3, 2020 at 3:55 PM Michael Gibney <mi...@michaelgibney.net>
wrote:

> Arturas,
> I think your syntax is wrong for the range subfacet? -- the configuration
> of the range facet should be directly under the `tt` key, rather than
> nested under `t_buckets` in the request. (The response introduces a
> "buckets" attribute that is not part of the request syntax).
> Michael
>
> On Thu, Dec 3, 2020 at 3:47 AM Arturas Mazeika <ma...@gmail.com> wrote:
>
> > Hi Solr Team,
> >
> > I am trying to check how I can formulate facet queries using JSON
> format. I
> > can successfully formulate query, range, term queries, as well as nested
> > term queries. How can I formulate a nested facet query involving "query"
> as
> > well as "range" formulations? The following does not work:
> >
> >
> > GET http://localhost:5555/solr/db/query HTTP/1.1
> > content-type: application/json
> >
> > {
> >     "query"  : "*:*",
> >     "limit"  : 0,
> >     "facet": {
> >         "a1": { "query":  "cfname2:1" },
> >         "a2": { "query":  "cfname2:2" },
> >         "a3": { "field":  "cfname2", "type":"terms", "prefix":"3" },
> >         "a4": { "query":  "cfname2:4" },
> >         "a5": { "query":  "cfname2:5" },
> >         "a6": { "query":  "cfname2:6" },
> >
> >         "tt": {
> >             "t_buckets": {
> >                 "type":  "range",
> >                 "field": "t",
> >                 "sort": { "t": "asc" },
> >                 "start": "2018-05-02T17:00:00.000Z",
> >                 "end":   "2020-11-16T21:00:00.000Z",
> >                 "gap":   "+1HOUR"
> >             }
> >         }
> >     }
> > }
> >
> > Single (not nested facets separately on individual queries as well as for
> > range) work in flying colors.
> >
> > Cheers,
> > Arturas
> >
>

Re: nested facets of query and terms type in JSON format

Posted by Michael Gibney <mi...@michaelgibney.net>.
Arturas,
I think your syntax is wrong for the range subfacet? -- the configuration
of the range facet should be directly under the `tt` key, rather than
nested under `t_buckets` in the request. (The response introduces a
"buckets" attribute that is not part of the request syntax).
Michael

On Thu, Dec 3, 2020 at 3:47 AM Arturas Mazeika <ma...@gmail.com> wrote:

> Hi Solr Team,
>
> I am trying to check how I can formulate facet queries using JSON format. I
> can successfully formulate query, range, term queries, as well as nested
> term queries. How can I formulate a nested facet query involving "query" as
> well as "range" formulations? The following does not work:
>
>
> GET http://localhost:5555/solr/db/query HTTP/1.1
> content-type: application/json
>
> {
>     "query"  : "*:*",
>     "limit"  : 0,
>     "facet": {
>         "a1": { "query":  "cfname2:1" },
>         "a2": { "query":  "cfname2:2" },
>         "a3": { "field":  "cfname2", "type":"terms", "prefix":"3" },
>         "a4": { "query":  "cfname2:4" },
>         "a5": { "query":  "cfname2:5" },
>         "a6": { "query":  "cfname2:6" },
>
>         "tt": {
>             "t_buckets": {
>                 "type":  "range",
>                 "field": "t",
>                 "sort": { "t": "asc" },
>                 "start": "2018-05-02T17:00:00.000Z",
>                 "end":   "2020-11-16T21:00:00.000Z",
>                 "gap":   "+1HOUR"
>             }
>         }
>     }
> }
>
> Single (not nested facets separately on individual queries as well as for
> range) work in flying colors.
>
> Cheers,
> Arturas
>