简体   繁体   中英

Elasticsearch pipeline to extract fields of an object to a root of document

I'm looking for a way to extract the contents of an object such as

{
    "mdc":{
      "key1": "value1",
      "key2": "value2",
      ...
    }
}

and transform that into

{
       "key1": "value1",
       "key2": "value2",
       ...
        "mdc":{
          "key1": "value1",
          "key2": "value2"
        }
}

I was looking at the provided processors but couldn't find anything useful.

My initial thought was to:

  • specify a field whose contents I can regex match or select in such another way
  • iterate over them
  • inline the their contents to new fields.

Any suggestions would be greatly appreciated!

It wasn't that hard after all.

   {
      "mdcflatten": {
        "processors": [
          {
            "script": {
              "lang": "painless",
              "inline": " ctx.mdc.keySet().each (key -> ctx[key] = ctx.mdc.get(key))"
            }
          },
          {
            "remove": {
              "field": "mdc"
            }
          }
        ]
      }

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM