Get document from doc_count

Is there a way to get document after composite aggregation?
Assume after I aggregated and I get doc_count = 5.
I want to know these 5 documents in doc_count because I have to analyze these documents.

Would it be possible to share the whole query and the response? You can hide the fields and values.

I want to count how many user ant,bird,cat,elep have bought product a.
Assume my data look like these

{"Date":"20200515","product":["a","b","a","a","c"],"user":"ant","rank":"silver"}
{"Date":"20200515","product":["a","b","c","e","f"],"user":"ant","rank":"silver"}
{"Date":"20200515","product":["d","a","c","a","c"],"user":"bird","rank":"silver"}
{"Date":"20200515","product":["a","c","a","d","e"],"user":"cat","rank":"silver"}
{"Date":"20200515","product":["a","b","a","a","f"],"user":"cat","rank":"silver"}
{"Date":"20200515","product":["a","b","a","c","d"],"user":"elep","rank":"silver"}

And my query look like this

{
  "aggs":{
      "comp":{
         "composite":{
            "sources":[
               {
                  "log_date":{
                     "terms":{
                        "field":"Date.keyword"
                     }
                  }
               },
               {
                  "product":{
                     "terms":{
                        "field":"product.keyword",
                        "missing_bucket":true
                     }
                  }
               },
               {
                  "rank":{
                     "terms":{
                        "field":"rank.keyword",
                        "missing_bucket":true
                     }
                  }
               },
               {
                  "user":{
                     "terms":{
                        "field":"user.keyword",
                        "missing_bucket":true
                     }
                  }
               }
            ]
         }
      }
  }
}

and this is my result

Date      user rank    product doc_count
20200515  ant  silver    a        2
20200515  bird silver    a        1  
20200515  cat  silver    a        2
20200515  elep silver    a        1
...

And this is my expect result

Date      user rank    product doc_count amount
20200515  ant  silver    a        2        4
20200515  bird silver    a        1        2
20200515  cat  silver    a        2        5
20200515  elep silver    a        1        2

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