Search query issue


(Fırat) #1

Hi Everyone,
My problem is about filter and get terms.
İ wanna get term counts like zalando.de 1
When i clicked any color other colors not seeing after refresh.
I could not found any example for nested products and filters.

// My index
PUT products
{
  "mappings": {
    "product": {
      "properties": {
        "name": { "type": "text" },
        "permalink": { "type": "text" },
        "images": {"type" : "text"},
        "variations": {
          "type": "nested",
          "properties": {
            "size": { "type": "keyword" },
            "color": { "type": "keyword" },
            "brand": { "type": "keyword" },
            "brand-slug": { "type": "keyword" },
            "price": {"type": "double" },
            "sale_price": {"type": "double" },
            "stock": {"type": "integer" }
          }
        },
        "categories": {
          "type": "nested",
          "properties": {
            "id": { "type": "integer" },
            "name": { "type": "keyword" },
            "slug": { "type": "keyword" }
          }
        }
      }
    }
  }
}

//My search code with Aggretions

{
  "from": 0,
  "size": 12,
  "aggs": {
    "nested_colors": {
      "nested": {
        "path": "variations"
      },
      "aggs": {
        "colors": {
          "terms": {
            "field": "variations.color"
          },
          "aggs": {
            "reverse_nested_colors": {
              "reverse_nested": {}
            }
          }
        }
      }
    },
    "nested_sizes": {
      "nested": {
        "path": "variations"
      },
      "aggs": {
        "sizes": {
          "terms": {
            "field": "variations.size"
          },
          "aggs": {
            "reverse_nested_sizes": {
              "reverse_nested": {}
            }
          }
        }
      }
    },
    "nested_categories": {
      "nested": {
        "path": "categories"
      },
      "aggs": {
        "colors": {
          "terms": {
            "field": "categories.name"
          },
          "aggs": {
            "reverse_nested_categories": {
              "reverse_nested": {}
            }
          }
        }
      }
    },
    "nested_markes": {
      "nested": {
        "path": "variations"
      },
      "aggs": {
        "markes": {
          "terms": {
            "field": "variations.brand-slug"
          },
          "aggs": {
            "reverse_nested_markes": {
              "reverse_nested": {}
            }
          }
        }
      }
    }
  },
  "query": {
    "bool": {
      "must": [
        {
          "nested": {
            "query": {
              "bool": {
                "must": [
                  {
                    "term": {
                      "variations.color": "Blau"
                    }
                  },
                  {
                    "term": {
                      "variations.size": "W30/L32"
                    }
                  },
                  {
                    "term": {
                      "variations.brand-slug": "yazubi"
                    }
                  }
                ]
              }
            },
            "path": "variations"
          }
        },
        {
          "nested": {
            "query": {
              "bool": {
                "must": [
                  {
                    "match": {
                      "categories.slug": "herren"
                    }
                  }
                ]
              }
            },
            "path": "categories"
          }
        }
      ]
    }
  }
}

(David Pilato) #2

Could you change the title to something more meaningful please?


(Mark Walkom) #3

Please don't post the same question more than once, it makes it harder for people to assist.


(Mark Walkom) #4