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 <maze...@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 <mich...@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 <maze...@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
> > >
> >
>

Reply via email to