How to create presets(theme styles) for shopify theme? - json

I'm creating a custom theme by using dawn as reference theme. I want to create 2 presets which changes all the default colors of my header, footer, announcement bar, mobile navbar, sections and the general settings.
Now i managed to change the colors of the general settings by setting the preset name and general setting variables in settings_data.json but can't seem to figure out how to change section colors. Tried alot of stuff there but it didn't work. Here's my code
{
"current": "Beige",
"presets": {
"Beige": {
"placeholder_color": "#F8E6DA",
"pagination_tab_bg_color": "#FFF8F2",
"pagination_number_color": "#000000",
"pagination_current_page_color": "#F8E6DA",
"pagination_arrow_tab_color": "#F8E6DA",
"button_hover": "#EFF6FF",
"customer_pages_bg_colors": "#ffffff",
"container_bg_color": "#FFF8F2",
"border_color": "#F8E6DA",
"primary_button_color": "#000000",
"predictive_search_bg_color": "#F8E6DA",
"predictive_search_button_color": "#FABF9D",
"predictive_search_button_text_color": "#000000",
"cart_notify_bg_color": "#FFF8F2",
"cart_notify_border_color": "#F8E6DA",
"cart_notify_primary_button_color": "#FABF9D",
"cart_notify_primary_button_text_color": "#000000",
"cart_notify_secondary_button_color": "#000000",
"cart_count_bubble_color": "#303036",
"gift_card_bg_color": "linear-gradient(#FFF1E8, #EFD1B8)",
"gift_card_badge_color": "#F8E6DA",
"gift_card_badge_text_color": "#000000",
"gift_card_primary_button_color": "#fabf9d",
"gift_card_secondary_button_color": "#000000",
"sections": {
"announcement-bar": {
"type": "announcement-bar",
"blocks": {
"announcement-bar-0": {
"type": "announcement",
"settings": {
"show_announce_home_page": false,
"text": "Welcome to our store",
"announce_font_size": 15,
"announce_text_align": "center",
"announce_bold": false,
"link": "",
"announce_text_color": "#E22120",
"announce_bg_color": "#ffffff"
}
}
},
"block_order": [
"announcement-bar-0"
],
"settings": {
}
},
"mobile-navigation": {
"type": "mobile-navigation",
"settings": {
"nav-menu": "main-menu",
"mobile_nav_text_color": "#000000",
"icon_color": "#000000",
"border_bottom": "#f8e6da",
"mobile_nav_bg_color": "#ffffff"
}
},
"header": {
"type": "header",
"settings": {
"logo_width": 100,
"menu": "main-menu",
"enable_sticky_header": true,
"show_search_box": true,
"enable_predictive_search": true,
"header_text_color": "#000000",
"icon_color": "#000000",
"header_bg_color": "#f8e6da",
"dropdown_hover_color": "#ebd3c3",
"dropdown_hover_text_color": "#000000"
}
},
"footer": {
"type": "footer",
"blocks": {
"footer-0": {
"type": "text",
"settings": {
"address": "<p>(218) 463-0260 36979 300th St<br\/>Roseau, Minnesota(MN), 56751<\/p>",
"contact": "<p>+1 (234) 567-89-90 <br\/>+1 (234) 567-89-90<\/p>",
"email": "info#collector.com"
}
},
"footer-1": {
"type": "menu",
"settings": {
"menu_heading": "Links",
"menu": "footer",
"menu_collapse": true
}
},
"88236e16-1b6c-438e-8543-f6fe494e04fb": {
"type": "menu",
"settings": {
"menu_heading": "Quick Links",
"menu": "footer-menu2",
"menu_collapse": true
}
},
"footer-2": {
"type": "info",
"settings": {
"additional_info": "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc quis risus mi. Ut placerat quam lectus. Curabitur dictum velit non lacus<\/p>"
}
},
"footer-3": {
"type": "newsletter",
"settings": {
"newsletter_heading": "Subscribe to our emails",
"newsletter_btn_text": "Sign Up",
"newsletter_caption": "Phasellus dignissim, tellus in pellentesque mollis, mauris",
"newsletter_btn_color": "#fabf9d",
"newsletter_btn_text_color": "#000000"
}
}
},
"block_order": [
"footer-0",
"footer-1",
"88236e16-1b6c-438e-8543-f6fe494e04fb",
"footer-2",
"footer-3"
],
"settings": {
"footer_logo_width": 100,
"footer_top_bg_color": "#f8e6da",
"footer_top_text_color": "#000000",
"footer_bottom_bg_color": "#303036",
"footer_bottom_text_color": "#ffffff",
"show_social": true,
"payment_enable": true
}
}
},
"content_for_index": [
]
},
"Electronic": {
"placeholder_color": "#7DABE0",
"pagination_tab_bg_color": "#F8FBFF",
"pagination_current_page_color": "#EFF6FF",
"pagination_arrow_tab_color": "#EFF6FF",
"button_hover": "#EBD3C3",
"customer_pages_bg_colors": "#FCFEFF",
"container_bg_color": "#EFF6FF",
"border_color": "#134074",
"primary_button_color": "#E0691E",
"predictive_search_bg_color": "#C6D8ED",
"predictive_search_button_color": "#E0691E",
"predictive_search_button_text_color": "#ffffff",
"cart_notify_bg_color": "#EFF6FF",
"cart_notify_border_color": "#134074",
"cart_notify_primary_button_color": "#ED6F1E",
"cart_notify_primary_button_text_color": "#ffffff",
"cart_notify_secondary_button_color": "#134074",
"cart_count_bubble_color": "#ED6F1E",
"gift_card_bg_color": "linear-gradient(#EFF6FF, #7DABE0)",
"gift_card_badge_color": "#000000",
"gift_card_badge_text_color": "#ffffff",
"gift_card_primary_button_color": "#ED6F1E",
"gift_card_primary_text_button_color": "#ffffff",
"gift_card_secondary_button_color": "#134074",
"sections": {
"announcement-bar": {
"type": "announcement-bar",
"blocks": {
"announcement-bar-0": {
"type": "announcement",
"settings": {
"show_announce_home_page": false,
"text": "Welcome to our store",
"announce_font_size": 15,
"announce_text_align": "center",
"announce_bold": false,
"link": "",
"announce_text_color": "#E22120",
"announce_bg_color": "#ffffcf"
}
}
},
"block_order": [
"announcement-bar-0"
],
"settings": {
}
},
"mobile-navigation": {
"type": "mobile-navigation",
"settings": {
"nav-menu": "main-menu",
"mobile_nav_text_color": "#000000",
"icon_color": "#000000",
"border_bottom": "#f8e6da",
"mobile_nav_bg_color": "#fff7f2"
}
},
"header": {
"type": "header",
"settings": {
"logo_width": 100,
"menu": "main-menu",
"enable_sticky_header": true,
"show_search_box": true,
"enable_predictive_search": true,
"header_text_color": "#000000",
"icon_color": "#000000",
"header_bg_color": "#f8e6da",
"dropdown_hover_color": "#ebd3c3",
"dropdown_hover_text_color": "#000000"
}
},
"footer": {
"type": "footer",
"blocks": {
"footer-0": {
"type": "text",
"settings": {
"address": "<p>(218) 463-0260 36979 300th St<br\/>Roseau, Minnesota(MN), 56751<\/p>",
"contact": "<p>+1 (234) 567-89-90 <br\/>+1 (234) 567-89-90<\/p>",
"email": "info#collector.com"
}
},
"footer-1": {
"type": "menu",
"settings": {
"menu_heading": "Links",
"menu": "footer",
"menu_collapse": true
}
},
"88236e16-1b6c-438e-8543-f6fe494e04fb": {
"type": "menu",
"settings": {
"menu_heading": "Quick Links",
"menu": "footer-menu2",
"menu_collapse": true
}
},
"footer-2": {
"type": "info",
"settings": {
"additional_info": "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc quis risus mi. Ut placerat quam lectus. Curabitur dictum velit non lacus<\/p>"
}
},
"footer-3": {
"type": "newsletter",
"settings": {
"newsletter_heading": "Subscribe to our emails",
"newsletter_btn_text": "Sign Up",
"newsletter_caption": "Phasellus dignissim, tellus in pellentesque mollis, mauris",
"newsletter_btn_color": "#fabf9d",
"newsletter_btn_text_color": "#000000"
}
}
},
"block_order": [
"footer-0",
"footer-1",
"88236e16-1b6c-438e-8543-f6fe494e04fb",
"footer-2",
"footer-3"
],
"settings": {
"footer_logo_width": 100,
"footer_top_bg_color": "#f8e6da",
"footer_top_text_color": "#000000",
"footer_bottom_bg_color": "#303036",
"footer_bottom_text_color": "#ffffff",
"show_social": true,
"payment_enable": true
}
}
},
"content_for_index": [
]
}
}
}
The general settings variables work with the change in style but others like announcement bar, mobile-nav, header, footer doesn't work.. my index file is in json format.
Is anything here we can do to fix this problem?

Unfortunately, Shopify presets are just general settings presets, if, for example, you have colors in your sections the only way to create two presets is two create two different sections presets, this solution creates two sections in the section selector in the theme editor for the same section. That's why it's not recommended to add colors to sections and use color schemas instead. (just like in Dawn)

Related

Card_V2 display issue in Google Chat

I have the following JSON to display Card_V2 for Google Chat, (note: words with "let_" are variables):
{
"cards_v2": [
{
"card": {
"header": {
"title": "Create campaign",
"subtitle": "Please complete the following information",
"imageType": "CIRCLE",
"imageUrl": "let_avatar"
},
"sections": [
{
"widgets": [
{
"textInput": {
"label": "Campaign name",
"type": "SINGLE_LINE",
"name": "nCampaign",
"value": "let_campaign"
}
},
{
"textInput": {
"label": "Campaign subject",
"type": "SINGLE_LINE",
"name": "subject",
"value": "let_subject"
}
},
{
"textInput": {
"label": "User name",
"type": "SINGLE_LINE",
"name": "userName",
"value": "let_userName"
}
},
{
"buttonList": {
"buttons": [
{
"text": "Create campaign",
"color": {
"red": 0.502,
"green": 1,
"blue": 0.733,
"alpha": 1
},
"onClick": {
"action": {
"function": "create",
"parameters": []
}
}
},
{
"text": "Cancel",
"color": {
"red": 0.502,
"green": 1,
"blue": 0.733,
"alpha": 1
},
"onClick": {
"action": {
"function": "cancel",
"parameters": []
}
}
}
]
},
"horizontalAlignment": "CENTER"
}
]
}
]
}
}
]
}
My problem is that the "textInput" screen does not appear, but last week it did. Does anyone have any idea what's going on?
PS: the Card is the return of the onMessage(event) function in Google Apps Script

JQ: Filtering a massive json with nested arrays efficiently

I have a MASSIVE json file with lots of extraneous fields that I need to trim down to only include certain fields. I've made some headway on processing the file with jq but I've run into some difficulty when it comes to pulling information out of the nested arrays in the json file, and none of the solutions I've found have seemed to work for me.
My json data looks like this:
{
"results": [
{
"url": "https://someresult.com",
"id": 5192740,
"external_id": null,
"via": {
"channel": "web",
"source": {
"from": {},
"to": {},
"rel": null
}
},
"created_at": "2022-04-29T15:19:37Z",
"updated_at": "2022-04-29T15:19:38Z",
"type": null,
"subject": "My subject line",
"raw_subject": "My subject line ",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris et nulla ut sapien ultrices tempus.",
"priority": "normal",
"status": "new",
"recipient": "somebody#email.com",
"requester_id": 1234567891,
"submitter_id": 1234567891,
"assignee_id": null,
"organization_id": null,
"group_id": 123456789,
"collaborator_ids": [],
"follower_ids": [],
"email_cc_ids": [],
"forum_topic_id": null,
"problem_id": null,
"has_incidents": false,
"is_public": true,
"due_at": null,
"tags": [
"_tag_1",
"_tag_2",
"_tag_3"
],
"custom_fields": [
{
"id": 1500010396161,
"value": null
},
{
"id": 360009431333,
"value": "Keep this data"
},
{
"id": 360054304553,
"value": false
},
{
"id": 1900000317745,
"value": null
},
{
"id": 360002223154,
"value": null
},
{
"id": 360009431353,
"value": "Keep this too"
},
{
"id": 1500001920482,
"value": "Keep this data, as well!"
}
],
"followup_ids": [],
"ticket_form_id": 12345678912,
"brand_id": 112358,
"allow_channelback": false,
"allow_attachments": true,
"result_type": "ticket"
},
{
"url": "https://anotherresult.com",
"id": 5192741,
"external_id": null,
"via": {
"channel": "web",
"source": {
"from": {},
"to": {},
"rel": null
}
},
"created_at": "2022-04-18T15:19:37Z",
"updated_at": "2022-04-18T15:19:38Z",
"type": null,
"subject": "My other subject line",
"raw_subject": "My other subject line ",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris et nulla ut sapien ultrices tempus.",
"priority": "normal",
"status": "new",
"recipient": "somebody#email.com",
"requester_id": 1234567892,
"submitter_id": 1234567892,
"assignee_id": null,
"organization_id": null,
"group_id": 123456780,
"collaborator_ids": [],
"follower_ids": [],
"email_cc_ids": [],
"forum_topic_id": null,
"problem_id": null,
"has_incidents": false,
"is_public": true,
"due_at": null,
"tags": [
"_tag_1",
"_tag_2",
"_tag_3"
],
"custom_fields": [
{
"id": 1500010396161,
"value": null
},
{
"id": 360009431333,
"value": "Keep this data"
},
{
"id": 360054304553,
"value": false
},
{
"id": 1900000317745,
"value": null
},
{
"id": 360002223154,
"value": null
},
{
"id": 360009431353,
"value": "Keep this too"
},
{
"id": 1500001920482,
"value": "Keep this data, as well!"
}
],
"followup_ids": [],
"ticket_form_id": 12345678913,
"brand_id": 112359,
"allow_channelback": false,
"allow_attachments": true,
"result_type": "ticket"
}
],
"facets": null,
"meta": {
"has_more": true,
"after_cursor": "eyJmaWVsZCI6ImNyZWF0ZWRfYXQiLCJkZXNjIjp0cnVlLCJ0aWVCcmVha0ZpZWxkIjoiaWQiLCJ0aWVCcmVha0Rlc2MiOmZhbHNlLCJzb3J0VmFsdWVzIjpbMTY0NjQxNTc3MjAwMCwxNTA5NDY0NjMzNTYyXSwiZXhwb3J0ZWRUaHVzRmFyIjoxMDAwLCJzZXNzaW9uU3RhcnQiOjE2NTE1MTA1MDE3MDksImNyZWF0ZWRBdCI6MTY1MTUxMDUwMTgxNywic2FsdGVkUmVxdWVzdEhhc2giOjEwMTMwNTk0MjMsInNhbHRlZEN1cnNvckhhc2giOi0xMTE3Mzc0MjIxfQ==",
"before_cursor": null
},
"links": {
"prev": null,
"next": "https://myendpoint.site.com/api/v2/search/export.json?filter%5Btype%5D=ticket&page%5Bafter%5D=eyJmaWVsZCI6ImNyZWF0ZWRfYXQiLCJkZXNjIjp0cnVlLCJ0aWVCcmVha0ZpZWxkIjoiaWQiLCJ0aWVCcmVha0Rlc2MiOmZhbHNlLCJzb3J0VmFsdWVzIjpbMTY0NjQxNTc3MjAwMCwxNTA5NDY0NjMzNTYyXSwiZXhwb3J0ZWRUaHVzRmFyIjoxMDAwLCJzZXNzaW9uU3RhcnQiOjE2NTE1MTA1MDE3MDksImNyZWF0ZWRBdCI6MTY1MTUxMDUwMTgxNywic2FsdGVkUmVxdWVzdEhhc2giOjEwMTMwNTk0MjMsInNhbHRlZEN1cnNvckhhc2giOi0xMTE3Mzc0MjIxfQ%3D%3D&page%5Bsize%5D=1000&query=group%3A360000609273+created%3E6Months"
}
}
And I want to trim it down to this:
{
"results": [
{
"url": "https://someresult.com",
"created_at": "2022-04-29T15:19:37Z",
"subject": "My subject line",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris et nulla ut sapien ultrices tempus.",
"recipient": "somebody#email.com",
"tags": [
"_tag_1",
"_tag_2",
"_tag_3"
],
"os": "Keep this data",
"is_signed_in": false,
"phone_model": "Keep this too",
"channel": "Keep this data, as well!"
}
]
}
So far, I've been able to brute force it by deleting fields by typing them all out
jq 'del(.results[] | .url, .id, .external_id, .via, .updated_at, .type, .raw_subject, .priority, .status, .requester_id, .submitter_id, .assignee_id, .organization_id, .group_id, .collaborator_ids, .follower_ids, .email_cc_ids, .problem_id, .has_incidents, .is_public, .due_at, .forum_topic_id, .satisfaction_rating, .sharing_agreement_ids, .fields, .followup_ids, .ticket_form_id, .allow_channelback, .allow_attachments, .result_type)'
but that feels absurd (still, it works).
But when I try to delete or filter for the fields I want from the custom_fields array, I get stuck (Cannot index array with string "custom fields").
My question is twofold:
Is there a cleaner way I could be selecting which fields to keep rather than specifying which to delete?
How do I grab the fields I need from the nested array, and flattening them to the same level as the rest of the fields, while also renaming them?
You can use a mapping to keep track of the custom fields wanted :
!/usr/bin/env bash
jq '{"os" : 360009431333,
"is_signed_in": 360054304553,
"phone_model" : 360009431353,
"channel" : 1500001920482} as $mapping |
.results |= map(
{ url,created_at,subject,description,recipient,tags,
} +
(.custom_fields as $custom_fields |
$mapping |
with_entries(
.value |= (. as $id | $custom_fields[]?|select(.id==$id).value)
)
)
)' input.json
The following illustrates one approach to answering the twofold question:
.results |= map(
(.custom_fields | map(.value | select(. != null))) as $values
| {url, created_at, subject, description, recipient, tags,
os: $values[0],
is_signed_in: $values[1],
phone_model: $values[2],
channel: $values[3] } )
This however results in .results having length 2.

Repeating elements with Adaptive Cards Templating

I am creating an adaptive card that requires that I repeat some elements in an array using the Designer. I am trying to create a list of items for an invoice so I need to repeat items in the cart....
I have a template with this container with the element that need to be repeated:
{
"type": "Container",
"items": [
{
"type": "Container",
"items": [
{
"$data": "${items}",
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"items": [
{
"type": "TextBlock",
"wrap": true,
"text": "${quantity}"
}
],
"width": "auto"
},
{
"type": "Column",
"spacing": "Medium",
"items": [
{
"type": "TextBlock",
"wrap": true,
"text": "${product.name}"
}
],
"width": "stretch"
},
{
"type": "Column",
"items": [
{
"type": "TextBlock",
"text": "${cost}",
"wrap": true
}
],
"width": "auto"
},
{
"type": "Column",
"id": "chevronDown1",
"spacing": "Small",
"verticalContentAlignment": "Center",
"items": [
{
"type": "Image",
"selectAction": {
"type": "Action.ToggleVisibility",
"title": "collapse",
"targetElements": [
"cardContent1",
"chevronUp1",
"chevronDown1"
]
},
"url": "https://adaptivecards.io/content/down.png",
"width": "20px",
"altText": "collapsed"
}
],
"width": "auto"
},
{
"type": "Column",
"id": "chevronUp1",
"isVisible": false,
"spacing": "Small",
"verticalContentAlignment": "Center",
"items": [
{
"type": "Image",
"selectAction": {
"type": "Action.ToggleVisibility",
"title": "expand",
"targetElements": [
"cardContent1",
"chevronUp1",
"chevronDown1"
]
},
"url": "https://adaptivecards.io/content/up.png",
"width": "20px",
"altText": "expanded"
}
],
"width": "auto"
}
]
},
{
"type": "Container",
"id": "cardContent1",
"isVisible": false,
"items": [
{
"type": "Container",
"items": [
{
"type": "TextBlock",
"isSubtle": true,
"wrap": true,
"text": "${product.description}"
}
]
}
]
}
],
}
],
}
and sample data that looks something like this:
{
"items": [
{
"quantity": "1",
"unitCost": "55",
"cost": "55",
"product": {
"name": "Product 1",
"description": "Lorem ipsum dolor sit amet"
}
}, {
"quantity": "2",
"unitCost": "55",
"cost": "55",
"product": {
"name": "Product 2",
"description": "Lorem ipsum dolor sit amet"
}
}
]
}
I followed the example here but I cannot get the same effect... I am presuming it is cause I have nested elements.
to do what you want to achieve you need to use dynamically generated targetElements and ID's.
I used your template and fixed it to have a working example here:
https://www.madewithcards.io/cards/toggleable-description-in-array
Here's the code for reference:
{
"type": "AdaptiveCard",
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.2",
"body": [{
"type": "TextBlock",
"text": "Items:",
"size": "Medium",
"weight": "Bolder"
},
{
"type": "Container",
"$data": "${items}",
"items": [{
"type": "ColumnSet",
"columns": [{
"type": "Column",
"items": [{
"type": "TextBlock",
"wrap": true,
"text": "${quantity}"
}],
"width": "auto"
},
{
"type": "Column",
"spacing": "Medium",
"items": [{
"type": "TextBlock",
"wrap": true,
"text": "${product.name}"
}],
"width": "stretch"
},
{
"type": "Column",
"items": [{
"type": "TextBlock",
"text": "${cost}",
"wrap": true
}],
"width": "auto"
},
{
"type": "Column",
"id": "chevronDown${product.name}",
"spacing": "Small",
"verticalContentAlignment": "Center",
"items": [{
"type": "Image",
"selectAction": {
"type": "Action.ToggleVisibility",
"title": "collapse",
"targetElements": [
"${product.name}",
"chevronUp${product.name}",
"chevronDown${product.name}"
]
},
"url": "https://adaptivecards.io/content/down.png",
"width": "20px",
"altText": "collapsed"
}],
"width": "auto"
},
{
"type": "Column",
"id": "chevronUp${product.name}",
"isVisible": false,
"spacing": "Small",
"verticalContentAlignment": "Center",
"items": [{
"type": "Image",
"selectAction": {
"type": "Action.ToggleVisibility",
"title": "expand",
"targetElements": [
"${product.name}",
"chevronUp${product.name}",
"chevronDown${product.name}"
]
},
"url": "https://adaptivecards.io/content/up.png",
"width": "20px",
"altText": "expanded"
}],
"width": "auto"
}
]
},
{
"type": "Container",
"id": "${product.name}",
"isVisible": false,
"items": [{
"type": "Container",
"items": [{
"type": "TextBlock",
"isSubtle": true,
"wrap": true,
"text": "${product.description}"
}]
}]
}
]
}
]
}
The data is untouched and taken from your sample.

AdaptiveCardsJson - Click to call option without opening new URL

I've got a Json AdaptiveCard that presents information on employees in the business with their name, job title, phone number, email etc..
We've set it up to dial their telephone number on a click to call, but clicking the number opens up a new URL which we don't want. We want it as a background action.
How can we achieve this? Here's our code (Look at the section that has FaceSet, then a Telephone value, it's that value that creates the click to call:
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"actions": [
{
"type": "Action.OpenUrl",
"title": "Call",
"url": "dial:{{Phone}}"
}
],
"body": [
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "Image",
"url": "http://intranet.christiegroup.com/stafflisting/staff/{{Reference}}.jpg",
"size": "medium",
"style": "people"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "{{FullName}}",
"weight": "bolder",
"wrap": true
},
{
"type": "TextBlock",
"spacing": "none",
"text": "{{JobTitle}}",
"isSubtle": true,
"wrap": true
},
{
"type": "FactSet",
"facts": [
{
"title": "Telephone:",
"value": "[{{Phone}}](dial:{{Phone}})"
},
{
"title": "Mobile:",
"value": "{{Mobile}}"
},
{
"title": "Email:",
"value": "{{Email}}"
}
]
}
]
}
]
}
]
}

Get and attach all child documents with it's parent in a single query elasticsearch

I have an elastic search implementation with parent and child relationship.
The parent (products) type has two child types(productfeatures, supplierpna).
I have the search feature on my application which needs to return the parent document based on the productcode field in the "products" type.
What I need is to get all child documents attached to the parent as a sub nested list with a single filtered query.
e.g. productcode = "123456" will return 10 products but some products has the child object and some don't, but I want to get the parent document regardless the child document existence.
I tried has_child option but it do not return the parent document when there is no child objects
Here is my mapping, any help in this regard will be very helpful.
{ "itdealer": {
"aliases": {},
"mappings": {
"products": {
"properties": {
"categoryname": {
"type": "string",
"index_analyzer": "keylower",
"search_analyzer": "stem",
"fields": {
"categoryname_ags": {
"type": "string",
"index": "not_analyzed"
}
}
},
"highPic": {
"type": "string",
"index": "no",
"include_in_all": false
},
"id": {
"type": "string"
},
"longDescription": {
"type": "string"
},
"lowPic": {
"type": "string",
"index": "no",
"include_in_all": false
},
"manufacturername": {
"type": "string",
"index_analyzer": "keylower",
"search_analyzer": "stem",
"fields": {
"manufacturername_ags": {
"type": "string",
"index": "not_analyzed"
}
}
},
"modelName": {
"type": "string",
"index": "no",
"include_in_all": false
},
"productManualPdfUrl": {
"type": "string",
"index": "no",
"include_in_all": false
},
"productPdfUrl": {
"type": "string",
"index": "no",
"include_in_all": false
},
"productSpecifications": {
"type": "nested",
"include_in_parent": true,
"include_in_root": true,
"include_in_all": true,
"properties": {
"featureGroupName": {
"type": "string",
"index": "not_analyzed",
"index_analyzer": "keylower",
"include_in_all": true
},
"featureGroupName.featureName": {
"type": "string",
"index": "not_analyzed",
"index_analyzer": "keylower",
"include_in_all": true
},
"featureGroupName.featureValue": {
"type": "string",
"index": "not_analyzed",
"index_analyzer": "keylower",
"include_in_all": true
},
"productcode": {
"type": "string",
"index": "not_analyzed",
"index_analyzer": "special",
"include_in_all": true
}
}
},
"productcode": {
"type": "string",
"index": "not_analyzed",
"store": true,
"index_analyzer": "special"
},
"searchTerms": {
"type": "string",
"index_analyzer": "keylower",
"search_analyzer": "stem"
},
"shortDescription": {
"type": "string",
"store": true
},
"subCategoryname": {
"type": "string",
"index_analyzer": "keylower",
"search_analyzer": "stem",
"fields": {
"subCategoryname_ags": {
"type": "string",
"index": "not_analyzed"
}
}
},
"thumbPic": {
"type": "string",
"index": "no",
"include_in_all": false
},
"title": {
"type": "string",
"analyzer": "keylower",
"fields": {
"title_ac": {
"type": "string",
"index_analyzer": "pr_autocomplete",
"search_analyzer": "keylower"
},
"title_stem": {
"type": "string",
"index_analyzer": "stem",
"search_analyzer": "keylower"
}
}
},
"warrantyInfo": {
"type": "string",
"index": "no",
"include_in_all": false
}
}
},
"productfeatures": {
"_parent": {
"type": "products"
},
"_routing": {
"required": true
},
"properties": {
"featureGroupName": {
"type": "string",
"index": "not_analyzed",
"index_analyzer": "keylower"
},
"featureGroupName.featureName": {
"type": "string",
"index": "not_analyzed",
"index_analyzer": "keylower"
},
"featureGroupName.featureValue": {
"type": "string",
"index": "not_analyzed",
"index_analyzer": "keylower"
},
"features": {
"properties": {
"featureName": {
"type": "string"
},
"featureValue": {
"type": "string"
}
}
},
"productcode": {
"type": "string",
"index": "not_analyzed",
"index_analyzer": "special"
}
}
},
"supplierpna": {
"_parent": {
"type": "products"
},
"_routing": {
"required": true
},
"properties": {
"freeStock": {
"type": "string",
"index": "no",
"include_in_all": false
},
"manufacturer": {
"type": "string",
"index": "no",
"include_in_all": false
},
"partNumber": {
"type": "string",
"index": "not_analyzed",
"store": true,
"index_analyzer": "special"
},
"productcode": {
"type": "string",
"index": "not_analyzed",
"store": true
},
"rRP": {
"type": "double",
"store": true
},
"supplier": {
"type": "string",
"index": "not_analyzed",
"include_in_all": false
},
"supplierId": {
"type": "double",
"index": "no"
},
"supplierLogo": {
"type": "string",
"index": "no",
"include_in_all": false
},
"supplierName": {
"type": "string",
"index": "not_analyzed",
"index_analyzer": "keylower"
},
"supplierProductDescription": {
"type": "string",
"index": "no",
"include_in_all": false
},
"supplierURL": {
"type": "string",
"index": "no",
"include_in_all": false
},
"updatedDate": {
"type": "date",
"index": "no",
"format": "dateOptionalTime",
"include_in_all": false
}
}
}
},
"settings": {
"index": {
"mapping": {
"allow_type_wrapper": "true"
},
"search": {
"slowlog": {
"threshold": {
"fetch": {
"warn": "1s"
}
}
}
},
"number_of_shards": "5",
"merge": {
"policy": {
"merge_factor": "10"
}
},
"creation_date": "1432827491555",
"analysis": {
"filter": {
"special": {
"split_on_numerics": "false",
"generate_word_parts": "false",
"preserve_original": "true",
"generate_number_parts": "false",
"split_on_case_change": "false",
"type_table": [
"# => ALPHA",
"- => ALPHA",
"$ => ALPHA",
"% => ALPHA"
],
"type": "word_delimiter"
},
"stemming": {
"type": "stemmer",
"language": "light_english"
},
"autocomplete": {
"min_gram": "1",
"type": "edge_ngram",
"stopwords": "_english_",
"max_gram": "20"
}
},
"analyzer": {
"special": {
"filter": [
"lowercase",
"special"
],
"type": "custom",
"tokenizer": "keyword"
},
"keylower": {
"filter": "lowercase",
"tokenizer": "standard"
},
"pr_autocomplete": {
"type": "custom",
"filter": [
"lowercase",
"autocomplete"
],
"tokenizer": "standard"
},
"stem": {
"filter": [
"lowercase",
"stemming"
],
"type": "custom",
"tokenizer": "standard"
}
}
},
"number_of_replicas": "1",
"version": {
"created": "1050299"
},
"uuid": "D1spSYWURBWIfXYRcsY6cg"
}
},
"warmers": {}}}
My current normal search query data
{
"query": {
"filtered": {
"query": {
"multi_match": {
"fields": [
"searchTerms",
"manufacturername^7",
"subCategoryname^4",
"title_ac^10",
"categoryname",
"shortDescription",
"productcode"
],
"query": "hp desktop",
"type": "cross_fields",
"operator": "or",
"tie_breaker": 0.3
}
}
}
},
"size": "10",
"from": "0",
"aggs": {
"manufacture": {
"terms": {
"field": "manufacturername_ags",
"size": 0,
"order": {
"_count": "desc"
}
}
},
"category": {
"terms": {
"field": "categoryname_ags",
"size": 0,
"order": {
"_count": "desc"
}
}
},
"subcategory": {
"terms": {
"field": "subCategoryname_ags",
"size": 0,
"order": {
"_count": "desc"
}
}
}
}
}
Right now this query only returns the parent document I want this query to be modified so that I will include the child objects both (productfeatures and supplierpna) in each parent document.