2

Trying to use anchors in an additive way, Following YAML code will not work but can explain what I want it to do

  endpoint:
    data.updates.index.name: &UPDATES-INDEX-NAME "data-updates"
    meta.data.type.name: &DATA-TYPE-NAME "meta-data"
    last.run.type.name: &RUN-TYPE-NAME "lastrun"
    search.ctx: *UPDATES-INDEX-NAME "/" *DATA-TYPE-NAME "/_search"
    search.lastrun: *UPDATES-INDEX-NAME "/" *RUN-TYPE-NAME "/_search"
    update.lastrun: *UPDATES-INDEX-NAME "/" *RUN-TYPE-NAME "/"

a1: &anchor1 "hello" a2: &anchor2 "moon" property: *anchor1 "-" *anchor2

property should yield "hello-moon" is it possible at all? tried also using ${} instead of anchors

1 Answers1

1

This is not possible with YAML. The anchor/alias feature was designed for serializing cyclic data structures, not for re-using values inside expressions. In YAML, there are no expressions (well, except for the !!merge tag for YAML 1.1 which is outdated and does not help you here). You need to do all operations you want to do on your data while or after loading.

A possible way to do it:

endpoint:
  data.updates.index.name: "data-updates"
  meta.data.type.name: "meta-data"
  last.run.type.name: "lastrun"
  search.ctx: "{{data.updates.index.name}}/{{meta.data.type.name}}/_search"
  search.lastrun: "{{data.updates.index.name}}/{{last.run.type.name}}/_search"
  update.lastrun: "{{data.updates.index.name}}/{{last.run.type.name}}/"

As you see, I used non-YAML markup (in this case, mustache-like) as placeholder. You would need to postprocess the data after loading in order to replace the placeholders with proper content.

flyx
  • 35,506
  • 7
  • 89
  • 126