I have a document like this.
{
"pageName": "testtag1",
"tags": {
"primary": [
{
"groupName": "visitorSegments",
"id": "4d044b05-6523-40b4-9fea-ef04567e1f6e",
"tagName": "HXYZ",
"tagTitle": "HXYZ"
},
{
"groupName": "visitorSegments",
"id": "20a38ec7-3724-404a-bed9-d046ae3f60b7",
"tagName": "HABC",
"tagTitle": "HABC"
},
{
"groupName": "visitorSegments",
"id": "4066eac4-e9a1-4fd5-9175-2914644f16c3",
"tagName": "Int Test 1",
"tagTitle": "Int Test 1"
},
{
"groupName": "visitorSegments",
"id": "da8c775e-0968-4fcf-aedd-0b2ad105f9QA",
"tagName": "name with spaces",
"tagTitle": "title"
}
],
"secondary": [
{
"groupName": "visitorSegments",
"id": "48ee51d8-4f64-4a51-a207-84d55995d405",
"tagName": "TABC",
"tagTitle": "TABC"
},
{
"groupName": "visitorSegments",
"id": "842dc7cf-7d7b-4df6-9dff-f4a14af81027",
"tagName": "Test1111",
"tagTitle": "Test a - 0"
},
{
"groupName": "visitorSegments",
"id": "92eca3f0-1192-455b-b2cc-69926d5e7c5c",
"tagName": "Test a - 1",
"tagTitle": "Test a - 1"
},
{
"groupName": "visitorSegments",
"id": "b2a2c298-12ae-4cd4-a94f-b6b846bda583",
"tagName": "Int Test 2",
"tagTitle": "Int Test 2"
}
]
},
"type": "pqr",
}
And I am UNNESTING two arrays of primary and secondary tags and returning one tagtile value which matches either in primary or secondary matches the string “%test%”.
This is the query i am writing but not getting the desired result.
SELECT DISTINCT x.tagTitle, y.tagTitle as sec
FROM mydb
AS doc
UNNEST doc.tags.primary
AS x
UNNEST doc.tags.secondary AS y
WHERE doc.type=‘pqr’
AND (LOWER(x.tagTitle) LIKE “%test%”
OR LOWER(y.tagTitle) LIKE “%test%”)