Issue in solving nested aggregation

Hello, I have a "PRODUCT_SUPPLIER" index in which I have a documents of products with its suppliers, having fields name "product_name" and "product_supplier".

"mappings" : {
      "properties" : {
        "product_name" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword"
            }
          }
        },
        "product_supplier" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword"
            }
          }
        }
      }
    }

A product can have more than one supplier. I have a supplier name say "supplier1". I get the buckets of products this supplier supply. Now from that buckets i want to do query to get others supplier names of specific products in buckets except that supplier "supplier1". My query is this

GET /products_supplier/_search
{
  "query": {
    "term": {
      "product_supplier": {
        "value": "supplier1"
      }
    }
  }, "aggs": {
    "products_list": {
      "terms": {
        "field": "product_name.keyword",
        "size": 10
      }, "aggs": {
        "others_supplier": {
          "terms": {
            "field": "product_supplier.keyword",
            "size": 10
          }
        }
      }
    }
  }
}

I get following results. I don't know how to eliminate the "Supplier1" in the "others_supplier" aggragation.

{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 3,
      "relation" : "eq"
    },
    "max_score" : 0.6931472,
    "hits" : [
      {
        "_index" : "products_supplier",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 0.6931472,
        "_source" : {
          "product_name" : "maggie",
          "product_supplier" : "supplier1"
        }
      },
      {
        "_index" : "products_supplier",
        "_type" : "_doc",
        "_id" : "3",
        "_score" : 0.6931472,
        "_source" : {
          "product_name" : "potatoes",
          "product_supplier" : "supplier1"
        }
      },
      {
        "_index" : "products_supplier",
        "_type" : "_doc",
        "_id" : "4",
        "_score" : 0.6931472,
        "_source" : {
          "product_name" : "chips",
          "product_supplier" : "supplier1"
        }
      }
    ]
  },
  "aggregations" : {
    "products_list" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : "chips",
          "doc_count" : 1,
          "others_supplier" : {
            "doc_count_error_upper_bound" : 0,
            "sum_other_doc_count" : 0,
            "buckets" : [
              {
                "key" : "supplier1",
                "doc_count" : 1
              }
            ]
          }
        },
        {
          "key" : "maggie",
          "doc_count" : 1,
          "others_supplier" : {
            "doc_count_error_upper_bound" : 0,
            "sum_other_doc_count" : 0,
            "buckets" : [
              {
                "key" : "supplier1",
                "doc_count" : 1
              }
            ]
          }
        },
        {
          "key" : "potatoes",
          "doc_count" : 1,
          "others_supplier" : {
            "doc_count_error_upper_bound" : 0,
            "sum_other_doc_count" : 0,
            "buckets" : [
              {
                "key" : "supplier1",
                "doc_count" : 1
              }
            ]
          }
        }
      ]
    }
  }
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.