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

Json aggs #1760

Merged
merged 35 commits into from
Oct 31, 2014
Merged

Json aggs #1760

merged 35 commits into from
Oct 31, 2014

Conversation

w33ble
Copy link
Contributor

@w33ble w33ble commented Oct 28, 2014

Closes #1731

This had become a larger project than expected, partly because I started going about it the wrong way and created tests along the way for parts that weren't really related. But, at least more things have tests now...

This PR adds a JSON input to the agg builder. The intention is that you can take a JSON ES query from elsewhere, drop it in this input, and get the results in Kibana without having to build it by hand.

Note: Any JSON data put in this input will clobber input from any other fields in the agg builder.

  • adds raw_json param type and control, with tests (100%)
  • query_input component is now the validate_query directive, with tests (78%)
  • debounce service created, with tests (100%), and validate_query uses it instead of _.debounce
  • the input-error css class was abstracted out, with hopes to re-use it elsewhere (now in _input.less)
  • validate_json directive was added, with tests (100%)

@w33ble w33ble added the WIP label Oct 28, 2014
watch for the resolution of the promise repsonse to check to classes on the directive
@w33ble w33ble added review and removed WIP labels Oct 28, 2014
@spalger
Copy link
Contributor

spalger commented Oct 29, 2014

Looks like the json editor only shows up when the agg already has advanced params. Should show up on all aggs.

@spalger
Copy link
Contributor

spalger commented Oct 29, 2014

Besides previous comment 👍

@w33ble
Copy link
Contributor Author

w33ble commented Oct 29, 2014

@spenceralger advanced wasn't being shown because it wasn't always in the params (it was only in terms). The latest commit always appends the JSON type to all param types.

@w33ble w33ble closed this Oct 30, 2014
@w33ble w33ble reopened this Oct 30, 2014
w33ble added a commit that referenced this pull request Oct 31, 2014
@w33ble w33ble merged commit 040685a into elastic:master Oct 31, 2014
@tomercagan
Copy link

I new to Kibana so maybe my assumption is wrong.
From what I understand, if you input some json in the "JSON Input" text area (after clicking advanced) it should replace the aggregation selected (from above: Note: Any JSON data put in this input will clobber input from any other fields in the agg builder.).

I am trying to somehow use scripted_metric so I selected an arbitrary aggregation and field and then pasted my scripted metric into the JSON Input:

json_input

But in reality, the json was added into the sum aggregation (I extracted this query from the error report):

{
  "query": {
    "filtered": {
      "query": {
        "query_string": {
          "query": "*"
        }
      },
      "filter": {
        "bool": {
          "must": [
            {
              "range": {
                "mts": {
                  "gte": 1418767200000,
                  "lte": 1418987718938
                }
              }
            }
          ],
          "must_not": []
        }
      }
    }
  },
  "size": 0,
  "aggs": {
    "2": {
      "date_histogram": {
        "field": "mts",
        "interval": "3600000ms",
        "min_doc_count": 1,
        "extended_bounds": {
          "min": 1418767200000,
          "max": 1418987718936
        }
      },
      "aggs": {
        "1": {
          "sum": {
            "field": "M8000C0",
            "aggs": {
              "kpi1": {
                "scripted_metric": {
                  "init_script": "_agg. sumVal1 = 0; _agg.sumVal2 = 0;",
                  "map_script": "_agg.sumVal1 += doc.val1; _agg.sumVal2 += doc.val2;",
                  "reduce_script": "totalVal1 = 0; totalVal2 = 0; for (agg in _aggs) {  totalVal1 += agg.sumVal1; totalVal2 += agg.sumVal2;}; return totalVal2/ totalVal1"
                }
              }
            }
          }
        }
      }
    }
  },
  "fields": [
    "*",
    "_source"
  ],
  "script_fields": {
    "mts": {
      "script": "if (doc['mts'].value == 0) { null } else { doc['mts'].value }"
    }
  }
}

Is this an error in my assumptions about the json actually replacing the aggregation or is this some edge case not covered?

@jvienne
Copy link

jvienne commented Dec 24, 2014

I have a similar problem trying to visualise the query of the following exemple in Kibana:

http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/children-agg.html

I add a term aggregation with the country field and then try to add the children aggregation using the JSON Input area:

24-12-2014 10-43-11

The JSON is not added in the expected place:

24-12-2014 10-46-59

Is it a bug or an incorrect use of the JSON Input area?

Thank a lot!!

@spalger
Copy link
Contributor

spalger commented Dec 24, 2014

Hey @tomercagan @jvienne I think you misunderstood the purpose of the JSON input in the agg builder; it is for defining or overriding parameters/arguments for a specific aggregation. It can not add arbitrary aggregations to the visualization.

This is likely to always be the case, as we need to know what an aggregation does in order to read it's results, use its results to create bars/slices/lines/etc, format the values it produces, and label the visual elements it creates. Sorry for the confusion!!

Maybe we could describe the capabilities of this input a bit better in the UI.

@tomercagan
Copy link

Hi @spenceralger - thanks for the response.
Is there some way to do something like that?

I am not sure about children aggregation but it seems to me that metric aggregation is very similar to any "arithmetic" aggregation - it results in one value per bucket (though this value could be an object).

Thanks!

@spalger
Copy link
Contributor

spalger commented Dec 30, 2014

@tomercagan no problem. Currently there isn't any way to do that but we are investigating adding the top hits agg once #1536 is complete. Maybe the "children" agg will come around that time.

@jvienne
Copy link

jvienne commented Jan 5, 2015

@spenceralger thanks for your answer!

There is no way to visualise a children aggregation?

@spalger
Copy link
Contributor

spalger commented Jan 5, 2015

Correct

@w33ble w33ble deleted the json-aggs branch February 6, 2015 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSON input in agg builder
4 participants