在聚合中指定索引过滤器的 Elasticsearch



我有一个弹性查询聚合,我需要根据索引名称过滤聚合。查询部分实际上在多个索引上工作,但我想过滤特定索引的聚合。请帮助我如何在聚合中传递索引过滤器 -

{       
    "query": {
        "bool": {
            "filter": [
                {
                    "bool": {
                        "should": [
                            {
                                "query_string": {
                                    "fields": [
                                        "productDesc",
                                        "productDescription"
                                    ],
                                    "default_operator": "AND",
                                    "query": "machine"
                                }
                            }
                        ]
                    }
                }
            ],
            "must": [ ],
            "must_not": [ ]
        }
    },
    "size": 0,
    "aggs": {
        "RelatedKeywords": { //here I want to add filter of index
            "sampler": {
                "shard_size": 20
            },
            "aggregations": {
                "keywords": {
                    "significant_text": {
                        "field": "productDesc",
                        "size": 100,
                        "filter_duplicate_text": true
                    }
                }
            }
        }
    }
}
你可以

这样做:

{
  "aggs": {
    "index": {
      "filter": {
        "term": {
          "_index": "index-name"
        }
      },
      "aggs": {
        "RelatedKeywords": {
          "sampler": {
            "shard_size": 20
          },
          "aggregations": {
            "keywords": {
              "significant_text": {
                "field": "productDesc",
                "size": 100,
                "filter_duplicate_text": true
              }
            }
          }
        }
      }
    }
  }
}

最新更新