1
votes

I am using the new (beta)-feature called "composite-aggrgeations" in elasticsearch. The main purpose for me is the added scrolling-functionality of this aggregation. I am actually using it on one source only.

Now I have found that using the "min_doc_count"-parameter on a terms-aggregation will produce the error:

failed to parse field [sources] ... unknown field [min_doc_count]

When I remove the composite feature from the aggregation everything works fine. (the terms-aggregation including the min-doc-count). It only fails when it is declared as a source in a composite-aggregation.

Is this a bug? Or maybe I did not fully understand composite-aggregations?

Thanks for any feedback!

Edit:

{
"aggs" : {
    "my_buckets": {
        "composite" : {
            "sources" : [
                { "product": { "terms" : { "field": "product", "min_doc_count": 2 } } }
            ]
        }
    }
 }

}

2
Can you show your query?Val
I edited the question :-)Tobias Gassmann

2 Answers

0
votes

The option min_doc_count is not supported by composite aggregations. See here.

0
votes

I had the same question you had and I found that, for implementing the filter by "min_doc_count", you have to make use of a sub-aggregation under your current search. And in this sub-aggregation, use "bucket_selector" and the "script" filtering by "doc_count", take the following snippet as example (is similar to what I used to accomplish my goal):

GET store_dept_*/_search?
{
  "aggs": {
    "table": {
      "composite": {
        "size": 20000,
        "sources": [
          {
        "stk1": {
          "terms": {
            "field": "store"
          }
        }
      },
      {
        "stk2": {
          "terms": {
            "field": "item",
            "order": "asc"
          }
        }
      }
    ]
  },
  "aggs": {
      "filter": {
        "bucket_selector": {
          "buckets_path": {
            "doc_count": "_count"
          },
          "script": "params.doc_count >= 10 && params.doc_count <= 100"
        }
     }
  }
}
  }
}