Union two fields within Vega

Hello together,

I am looking for a way to union the elements of two different fields into one (new) array in Vega (If this is already possible in an Elastic Query that's also fine).
It should be similar to a SQL-Statement like "select A as NewField from TableA UNION Select B as NewField from TableB"

I run the query _source["main_entities_location","main_entities_person"] which gives me the following data.
Union snip

I want to union all the entries of "main_entities_location" with the entries of "main_entities_person" in one new field/array to be able to do a wordcloud transform afterwards.

Thanks and kind regards

How about using runtime mappings if performance is acceptable?

GET /test_union/_search?filter_path=hits.hits.fields
{
  "runtime_mappings": {
    "united": {
      "type": "keyword",
      "script": {
        "source": """
          for (field in params.fields) {
            for (val in doc[field]){
              emit(val)
            }
          }
        """,
        "params":{
          "fields": ["location","person"]
        }
      }
    }
  },
  "fields": [
    "united"
  ]
}
{
  "hits" : {
    "hits" : [
      {
        "fields" : {
          "united" : [
            "Elon Musk",
            "Gwynne Shotwell",
            "Massachusetts",
            "United States"
          ]
        }
      }
    ]
  }
}

Thanks that works great in Dev-Console :slight_smile:
But how can I put this inside my data section with url-data call? I mean especially the GET- request part with "_search?filter_path=hits.hits.fields" which seem to be relevant parameter information

  "data": [
    {
      "name": "values",
      "url": {
        "%context%": true,
        "%timefield%": "first_date"
        "index": "clusters",
        "body": {
           ##My Query or Aggregtion inside here##
        }
      },
      "format": {"property": "something"},
      ...
      ...

That would most likely go in your format if you wanted to filter to that data. For your index just have the index name without the_search or filter.

"format": {"property": "hits.hits.fields"}
1 Like

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