How to add payload to request in Kibana vis plugin?

Hi,

I am writing a Kibana visualization plugin, would like to collect some input from UI and sent as payload along with REST request to ES (I have ES API Plugin intercepting all the rest requests to parse the payload), the best may be added to request body as below. I thought about to use Angular interceptor, but looks hacky and not clean. looking to see if some Kibana API can customizes the request?

Thanks,
KC

{
  "method": "POST",
  "transformRequest": [],
  "transformResponse": [],
  "url": "https://localhost:5601/vny/elasticsearch/_msearch",
  "data": "{"index":["abc-2016.01.18"],"ignore_unavailable":true,"preference":1484958913415}\n{"query":{"bool":{"must":[{"query_string":{"query":"*","analyze_wildcard":true}},{"range":{"@timestamp":{"gte":1451635200000,"lte":1483257599999,"format":"epoch_millis"}}}],"must_not":[]}},"size":0,"_source":{"excludes":[]},"aggs":{...}}\n",
  "cache": false,
  "headers": {
    "content-type": "application/x-ldjson",
    "Accept": "application/json, text/plain, */*"
  },
  "timeout": {
    "$$state": {
      "status": 0
    }
  }
}

Are you looking to make a request to Elasticsearch based on the UI input, or have that data persisted and added to all subsequent requests to Elasticsearch?

Hi @tsmalley,

We have our own UI to let users to write elasticsearch aggregations -- a simplified version of the standard ES query.
For example, UI input as below,
{"dimensions": [
{"type": "terms", "field": "fieldA"},
{"type": "terms", "field": "fieldB"},
{"type": "terms", "field": "fieldC"}
]
}

We want the UI input sent as payload along with the request generated by kibana e.g.
/_msearch
{"index":...}\n
{"query":{...},
"size":0,
"_source":{...},
"aggs": {...}
}\n

On our ES API plugin receiving the request, before reaching ES, the plugin converts the payload to standard ES aggs as below, and merge with the rest in the request, index, query, size, _source and so on. then send to ES to do the standard query. I was wondering what the best way to add UI inputs as request payload. Hope it makes sense :slight_smile:

{
  "aggs": {
    "2": {
      "terms": {
        "field": "fieldA",
        "size": 10,
        "order": {
          "_count": "desc"
        }
      },
      "aggs": {
        "3": {
          "terms": {
            "field": "fieldB",
            "size": 10,
            "order": {
              "_count": "desc"
            }
          },
          "aggs": {
            "4": {
              "terms": {
                "field": "fieldC",
                "size": 10,
                "order": {
                  "_count": "desc"
                }
              }
            }
          }
        }
      }
    }
  }
}

Thanks,
KC

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