How to exclude a filter from a facet?

Posted by gjb on Stack Overflow See other posts from Stack Overflow or by gjb
Published on 2013-03-26T23:16:44Z Indexed on 2014/06/04 3:25 UTC
Read the original article Hit count: 244

Filed under:

I have come from a Solr background and am trying to find the equivalent of "tagging" and "excluding" in Elasticsearch.

In the following example, how can I exclude the price filter from the calculation of the prices facet? In other words, the prices facet should take into account all of the filters except for price.

{
  query : {
    "filtered" : {
      "query" : {
        "match_all" : {}
      },
      "filter" : {
        "and" : [
          {
            "term" : {
              "colour" : "Red"
            }
          },
          {
            "term" : {
              "feature" : "Square"
            }
          },
          {
            "term" : {
              "feature" : "Shiny"
            }
          },
          {
            "range" : {
              "price" : { 
                "from" : "10",
                "to" : "20"
              }
            }
          }
        ]
      }
    }
  },
  "facets" : {
    "colours" : {
      "terms" : {
        "field" : "colour"
      }
    },
    "features" : {
      "terms" : {
        "field" : "feature"
      }
    },
    "prices" : {
      "statistical" : {
        "field" : "price"
      }
    }
  }
}

© Stack Overflow or respective owner

Related posts about elasticsearch