在弹性搜索中过滤子聚合内部

时间:2019-05-27 07:35:27

标签: elasticsearch

我尝试提取汇总数据,但是当我想要进一步过滤一组文档时,我有些迷茫。获得颜色似乎还可以,但是当我想用一些颜色过滤器聚合类别时,查询失败。我在此查询上做错什么了?

这是我已经拥有的查询:

GET/my_index/_search
{
  "_source": false,
  "aggs": {
    "global": {
      "global": {

      },
      "aggs": {
        "all_products": {
          "nested": {
            "path": "simple"
          },
          "aggs": {
            "filter_top": {
              "filter": {
                "bool": {
                  "must": [
                    {
                      "match": {
                        "simple.compound_words": {
                          "query": "tisch",
                          "operator": "AND"
                        }
                      }
                    }
                  ]
                }
              },
              "aggs": {
                "filter_merged": {
                  "aggs": {
                    "filter": {
                      "bool": {
                        "must": [
                          {
                            "terms": {
                              "simple.filter_color": [
                                "green",
                                "red"
                              ]
                            }
                          }
                        ]
                      }
                    },
                    "aggs": {
                      "filter_category": {
                        "terms": {
                          "field": "simple.filter_category"
                        }
                      }
                    }
                  }
                },
                "filter_color": {
                  "terms": {
                    "field": "simple.filter_color"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

这是索引映射的相关部分。

{
  "my_index": {
    "mappings": {
      "_doc": {
        "properties": {
          "simple": {
            "type": "nested",
            "properties": {
              "compound_words": {
                "type": "text",
                "analyzer": "GermanCompoundWordsAnalyzer"
              },
              "filter_category": {
                "type": "keyword"
              },
              "filter_color": {
                "type": "keyword"
              }
            }
          }
        }
      }
    }
  }
}

感谢您的支持。

0 个答案:

没有答案