There is no such thing as a perfect program, but that doesn’t discourage us, because writing a program is a constant pursuit of perfection.

Q: What are the features of Filter?

A:



Q: How do I use filter?

A:

# filter
PUT /filter_test
{
  "mappings" : {
    "properties" : {
      "brand" : {"type" : "keyword"},
      "color" : {"type" : "keyword"},
      "model" : {"type" : "keyword"}
    }
  }
}

# 索引
POST /filter_test/_doc/1
{
  "brand" : "gucci"."color" : "red"."model" : "slim"} # index POST /filter_test/_doc/2
{
  "brand" : "gucci"."color" : "yellow"."model" : "slim"} # index POST /filter_test/_doc/3
{
  "brand" : "gucci"."color" : "green"."model" : "slim"} # index POST /filter_test/_doc/4
{
  "brand" : "gucci"."color" : "blue"."model" : "slim"} # index POST /filter_test/_doc/5
{
  "brand" : "gucci"."color" : "blue"."model" : "llim"} # index POST /filter_test/_doc/6
{
  "brand" : "gucci"."color" : "yellow"."model" : "llim"} # index POST /filter_test/_doc/7
{
  "brand" : "gucci"."color" : "green"."model" : "llim"} # index POST /filter_test/_doc/8
{
  "brand" : "gucci"."color" : "red"."model" : "llim"GET /filter_test/_search {"query" : {
    "bool" : {
      "filter": [{"term" : {"brand" : "gucci"}}}}],"aggs" : {
    "color_aggs" : {
      "terms" : {
        "field" : "color"."size"  : 10}},"color_red" : {
      "filter" : {
        "term" : {
          "color" : "red"}},"aggs" : {
          "models" : {
            "terms" : {
              "field" : "model"."size"  : 10}}}}},"post_filter" : {
    "term" : {
      "color" : "red"}}}"took" : 0."timed_out" : false."_shards" : {
    "total" : 1."successful" : 1."skipped" : 0."failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 8."relation" : "eq"
    },
    "max_score" : 0.0."hits": [{"_index" : "filter_test"."_type" : "_doc"."_id" : "8"."_score" : 0.0."_source" : {
          "brand" : "gucci"."color" : "red"."model" : "llim"}}, {"_index" : "filter_test"."_type" : "_doc"."_id" : "Seven"."_score" : 0.0."_source" : {
          "brand" : "gucci"."color" : "green"."model" : "llim"}}, {"_index" : "filter_test"."_type" : "_doc"."_id" : "6"."_score" : 0.0."_source" : {
          "brand" : "gucci"."color" : "yellow"."model" : "llim"}}, {"_index" : "filter_test"."_type" : "_doc"."_id" : "5"."_score" : 0.0."_source" : {
          "brand" : "gucci"."color" : "blue"."model" : "llim"}}, {"_index" : "filter_test"."_type" : "_doc"."_id" : "4"."_score" : 0.0."_source" : {
          "brand" : "gucci"."color" : "blue"."model" : "slim"}}, {"_index" : "filter_test"."_type" : "_doc"."_id" : "3"."_score" : 0.0."_source" : {
          "brand" : "gucci"."color" : "green"."model" : "slim"}}, {"_index" : "filter_test"."_type" : "_doc"."_id" : "2"."_score" : 0.0."_source" : {
          "brand" : "gucci"."color" : "yellow"."model" : "slim"}}, {"_index" : "filter_test"."_type" : "_doc"."_id" : "1"."_score" : 0.0."_source" : {
          "brand" : "gucci"."color" : "red"."model" : "slim"}}}Copy the code