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
- Draw.io on a website
- Deploy elasticms on AWS
- Intégrer BOSA Accessibility Check dans un site web [Content in French]
- PHP - Convert Human Readable Size to Bytes
- Composer: How to use a specific branch acting like a specific revision in composer dependencies
- Stream a CSV from a JSON array
- Comment utiliser les commandes "locales" du skeleton [Content in French]
- How to extract data from a JsonMenuNestedEditorField
- Backup on AWS glacier
- Refer to environment variables in twig