Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to aggregate fields in nested objects in Kibana 4 #1989

Closed
benoitlouy opened this issue Nov 20, 2014 · 1 comment
Closed

Add support to aggregate fields in nested objects in Kibana 4 #1989

benoitlouy opened this issue Nov 20, 2014 · 1 comment

Comments

@benoitlouy
Copy link

Currently Kibana doesn't support aggregation of fields in nested objects as described there: http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/nested-aggregation.html#nested-aggregation

For instance, I have the following mapping:

{
    "mappings": {
        "decision": {
            "properties" : {
                "status": {"type": "string"},
                "timestamp": {"type": "date", "format": "yyyy-MM-dd'T'HH:mm:ss.SSSSSSZ"},
                "products": {
                    "properties": {
                        "name": {"type": "string"},
                        "status": {"type": "string"}
                    }
                }
            }
        }
    }   
}

and I am inserting document that look like this in my index:

{
    "products": [
        {
            "name": "product1",
            "status": "declined"
        },
        {
            "name": "product2",
            "status": "partial"
        }
    ],
    "status": "partial",
    "timestamp": "2014-11-19T15:45:23.219937Z"
}

I am trying to create a visualization that would show the count of document on the Y-axis, the timestamp on the X-axis and have split lines by products.name.
screen shot 2014-11-20 at 11 30 54 am

The aggregation request generated by Kibana 4 looks like this:

{
  "size": 0,
  "query": {
    "filtered": {
      "query": {
        "query_string": {
          "query": "*"
        }
      },
      "filter": {
        "bool": {
          "must": [
            {
              "range": {
                "timestamp": {
                  "gte": 1416412800000,
                  "lte": 1416500584849
                }
              }
            }
          ],
          "must_not": []
        }
      }
    }
  },
  "aggs": {
    "agg_52": {
      "date_histogram": {
        "field": "timestamp",
        "interval": "1800000ms",
        "min_doc_count": 1,
        "extended_bounds": {
          "min": "2014-11-19T16:00:00.000Z",
          "max": "2014-11-20T16:23:04.698Z"
        }
      },
      "aggs": {
        "agg_53": {
          "terms": {
            "field": "products.name",
            "size": 5,
            "order": {
              "_count": "desc"
            }
          }
        }
      }
    }
  }
}

when what I really want is this:

{
  "size": 0,
  "query": {
    "filtered": {
      "query": {
        "query_string": {
          "query": "*"
        }
      },
      "filter": {
        "bool": {
          "must": [
            {
              "range": {
                "timestamp": {
                  "gte": 1416409200000,
                  "lte": 1416498857349
                }
              }
            }
          ],
          "must_not": []
        }
      }
    }
  },
  "aggs": {
    "agg_10": {
      "date_histogram": {
        "field": "timestamp",
        "interval": "1800000ms",
        "min_doc_count": 1,
        "extended_bounds": {
          "min": "2014-11-19T15:00:00.000Z",
          "max": "2014-11-20T15:54:17.203Z"
        }
      },
      "aggs": {
        "products": {
          "nested": {
            "path": "products"
          },
          "aggs": {
            "agg_11": {
              "terms": {
                "field": "products.name",
                "size": 5,
                "order": {
                  "_count": "desc"
                }
              }
            }
          }
        }
      }
    }
  }
}

The difference being that the most nested aggs (aggs.agg_11) is nested within an aggs defining the nested path.

It'd be great if in the UI there was a way to surround any aggression by some custom json or even better if Kibana could detect nested objects.

@rashidkpc
Copy link
Contributor

duplicate of #1084, please add comments to that issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants