Search code examples
solr

Solr how to write a facet.query text field value


I am thoroughly confused and lost due to being unable to know what to enter in this facet.query field when using Solr

enter image description here

I want to do a sum of all the documents that are returned, summing up this TotalPaxCount and AdultPaxCount values?

How can I do this using the GUI in the Solr web interface. The very limited examples seem to use curl requests and I have tried what they put in the facet.query and its constantly errors.


Solution

  • I managed to see what the original code was creating and then gave up trying to use the web UI interface! using curl I could make a call like this, in windows I had to put it all on one line like this:

    curl http://localhost:8983/solr/mycore/query -d "{\"filter\": \"\",\"query\":\"ResortId:(229) AND ArrivalDate:[2022-10-24T00:00:00Z TO 2022-10-30T23:59:59Z] AND IsActive:True AND *:*\", \"limit\": 0,\"offset\": 0,\"fields\": \"\",\"facet\": {\"ResortId\": { \"type\": \"terms\",\"field\": \"ResortId\", \"limit\": -1, \"minCount\": 0, \"facet\": { \"Total\": \"sum(TotalCount)\", \"AdultCount\": \"sum(AdultCount)\", \"ChildCount\": \"sum(ChildCount)\", \"InfantCount\": \"sum(InfantCount)\" }}}}' 
    

    On a linux machine I believe you could do this curl command, which is more readable. I think this helps show the structure that is expect from solr, as was very confusing trying to understand the documentation.

    curl http://localhost:8983/solr/mycore/query -d '
    {
        "filter": "",
        "query": "ResortId:(229) AND ArrivalDate:[2022-10-24T00:00:00Z TO 2022-10-30T23:59:59Z] AND IsActive:True AND *:*",
        "limit": 0,
        "offset": 0,
        "fields": "",
        "facet": {
            "ResortId": {
                "type": "terms",
                "field": "ResortId",
                "limit": -1,
                "minCount": 0,
                "facet": {
                    "Total": "sum(TotalCount)",
                    "AdultCount": "sum(AdultCount)",
                    "ChildCount": "sum(ChildCount)",
                    "InfantCount": "sum(InfantCount)"
                }
            }
        }
    }'