Aggregations and filters both based on children documents


(Craig Longman) #1

Hello,

I'm trying to do some aggregations with children documents, but I also need to filter the results. The basic structure is:

document
   - folder { id }

So, for example, I want to get a count of documents that have a folder id of 100, 101 and 102.

The following works fine:

"aggs": {
  "to-children": {
    "children": {
      "type": "folder"
    },
    "aggs": {
      "x-value": {
        "terms": {
          "field": "folder_id_fi",
          "size": 0
        }
      }
    }
  }
}

But when I add the filter in like this:

{
  "aggs": {
    "to-children": {
      "children": {
        "type": "folder"
      },
      "aggs": {
        "x-value": {
          "filter": {
            "terms": {
              "folder_id_fi": [ 100, 101, 102 ]
            }
          },
          "aggs": {
            "x-value-field": {
              "terms": {
                "field": "folder_id_fi",
                "size": 0
              }
            }
          }
        }
      }
    }
  }
}

I get this response:

"aggregations": {
   "to-children": {
      "doc_count": 16852243,
      "x-value": {
         "doc_count": 0,
         "x-value-field": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": []
         }
      }
   }
}

So, it looks like the filter didn't work (the doc_count is the same as before the filter was added) and the bucket list is empty.

1.6.0 is the version of ES we're currently using (1.7.1 soon).

Thanks,

CraigL


(system) #2