Programmatically transform

Currently I’m using an elastic seach datasource. I have keys with values just like this:
(taken from UQL Parser | Grafana Plugins documentation)


[
  {
    "id": 1,
    "name": { "firstName": "john", "lastName": "doe" },
    "dob": "1985-01-01",
    "city": "chennai"
  },
  {
    "id": 2,
    "name": { "firstName": "alice", "lastName": "bob" },
    "dob": "1990-12-31",
    "city": "london"
  }
]

I would like to break it up into individual keys so I can flatten the json and visualize the output.

I figured out how to flatten this manually values using transform : How to extract json value from elasticsearch source

but this is tedious and manual. Is there a way I can interface with an API script transformations?

OR

I would like to use UQL to do this but I think UQL only talks to API datasources from what I can tell. I can’t seem to figure out how to use UQL on elasticsearch.

just point infinity to url:9200

what do you see with the data result from that?

1 Like

Oo this is promising so if I use just http://ip:9200
I see my table shows :
{ "cluster_name": "docker-cluster", "cluster_uuid": "v0UMqJ0MQiKrmg-ZaQ08pQ", "name": "elasticsearch", "tagline": "You Know, for Search", "version": { "build_date": "2022-08-23T11:08:48.893373482Z", "build_flavor": "default", "build_hash": "f65e9d338dc1d07b642e14a27f338990148ee5b6", "build_snapshot": false, "build_type": "docker", "lucene_version": "8.11.1", "minimum_index_compatibility_version": "6.0.0-beta1", "minimum_wire_compatibility_version": "6.8.0", "number": "7.17.6" } }

I got a curl to work :

curl -X POST "http://ip:9200/_sql?format=txt" -H 'Content-Type: application/json' -d '{"query": "SELECT \"label.keyword\" FROM \"indexName-*\""}'

But im not sure how to convert this curl into a URL options . For example where do I place the -d portion which has the query?

might want to read the docu

https://grafana.github.io/grafana-infinity-datasource/docs/url

can you please post a sample es document, I can try to spin one up locally and see what we can do

sample_es_doc.json (4.6 KB)

Sure here’s a sample document. I read the document link you posted… I my smooth brain just doesnt understand how to convert the curl statement which does return data successfully into something that fits in to the plugin parameters. Thanks

1 Like

please also post how to enable the sql method or can you also do vanilla json return type or can you do a json data return type on that sql type?

This should get you closer

uql

parse-json
| scope "hits.hits"

Transformation Extract

you can also play around with it using jsonata a feature of UQL

https://try.jsonata.org/HUzBvNlur

:fish: :fishing_pole_and_fish:

Thanks for the info, I actually don’t know how to “enable sql method” . But let me look into your example thanks