Search code examples
solrsolrjsolrcloud

Solr facet column with a condition


I have following facet query which is working fine. However as you can see I need from_usa as one more parameter, I have a country column and it needs to be conditional. Would that be possible ? I cant not use fq filters in this case.

{
            "facet":{
                "total_game_plays" : "count",
                "unique_game_players" : "unique(uuid)",
                "total_play_time":"sum(play_time)",
                //"from_usa": "unique(where country=US)"
            }
}

Solution

  • I assume you're using the JSON facet API from the syntax you've provioded, so a JSON facet query should do what you want:

    "from_usa": {
      "type": "query",
      "q": "country:US"
    }