Goal
When handling data in a elasticms JsonMenuNestedEditorField we should be able to parse the structure to get the content for the website search.
Computed field
The idea is to parse the Json menu, at finalization, in an computed field.
Regardless the type of container, let assume that I should extract those data fields:
- label
- body
- value
- sub-title
Here is the value template.
{% set data = {} %}
{% for item in _source.blocks|default('{}')|ems_json_menu_nested_decode %}
{% if item.label is defined %}
{% set data = data|merge([item.label]) %}
{% endif %}
{% if item.object.body is defined %}
{% set data = data|merge([item.object.body|striptags]) %}
{% endif %}
{% if item.object.value is defined %}
{% set data = data|merge([item.object.value]) %}
{% endif %}
{% if attribute(item.object, 'sub-title') is defined %}
{% set data = data|merge([attribute(item.object, 'sub-title')]) %}
{% endif %}
{% endfor %}
{{ data|json_encode|raw }}
To check what has been extracted define this Display template.
{{ data|json_encode }}
And finally the mapping to define:
{
"type" : "text",
"copy_to": "live_search"
}
Last posts
- elasticMS à la maison en haute disponibilité [Content in French]
- Draw.io on a website
- Deploy elasticms on AWS
- Intégrer BOSA Accessibility Check [Content in French]
- PHP - Convert Human Readable Size to Bytes
- Composer: use a branch as dependency
- Stream CSV from JSON
- Utiliser les commandes "locales" du skeleton [Content in French]
- Extract data from a JsonMenuNestedEditorField
- Backup on AWS glacier