Elasticsearch query to match a pattern and replace it with regex - regex

I have to get the TOP 5 hit APIs/Urls and display with the http statuses of each url and I am able to do it in a way with the below extraction query
{
"query": {
"bool": {
"must": [
{
"range": {
"#timestamp": {
"from": "now-15m",
"to": "now",
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"aggregations": {
"Url": {
"terms": {
"field": "data.url.keyword",
"size": 5,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
},
"aggregations": {
"Status": {
"terms": {
"field": "data.response.status",
"size": 5,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
}
}
}
}
}
}
Output :
"aggregations": {
"Url": {
"doc_count_error_upper_bound": 940,
"sum_other_doc_count": 52374,
"buckets": [
{
"Status": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"doc_count": 3,
"key": 200
},
{
"doc_count": 254,
"key": 400
}
]
},
"doc_count": 3515,
"key": "/account/me/"
},
{
"Status": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"doc_count": 3376,
"key": 200
}
]
},
"doc_count": 3385,
"key": "/PlanDetails"
},
{
"Status": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"doc_count": 3282,
"key": 200
}
]
},
"doc_count": 3282,
"key": "/evaluation"
},
{
"Status": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"doc_count": 3205,
"key": 200
}
]
},
"doc_count": 3205,
"key": "/user/me"
},
{
"Status": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"doc_count": 3055,
"key": 200
}
]
},
"doc_count": 3055,
"key": "/user"
}
]
}
}
}
But I have few URL where user ID comes inbetween the URLs.
For eg URLs like
/account/me/3417375321062014.cust
DJXXODKNPA1581975RI/PlanDetails
KXVEIPBYSR1597110677RI/payment
Because of distinct user ID inside the URL, elastic search considers these as separate one.
User ID is a mix of alphabets and numbers, sometimes only numbers and few only alphabets.
I need to replace these userID's in URL and count them as one
Lets say there are two hits with 200 status for /payment
DJXXODKNPA1583201975RI/payment
KXVEIPBYSR1597110677RI/payment
I should be able to replace the user ID with * and count as one API so I get output like
*/payment 200:2
But now it considers these as distinct URL/API, because of this I am unable to get the correct Top 5 Hit urls/APIs.
Any idea on this would be a great help. Thanks

Related

How to set or not set audio selector in AWS media convert?

I got this error, when creating job for AWS media convert:
Invalid selector_sequence_id [0] specified for audio_description [1].
I do not even need sound for my output mp4 video.
My intention is to loop for 2 second an image (png or jpg) and add a fade effect for the first frames.
How would you change the sent json?
{
"middlewareStack": {},
"input": {
"Queue": "arn:aws:mediaconvert:eu-central-1:634617701827:queues/Default",
"UserMetadata": {},
"Role": "arn:aws:iam::634617701827:role/service-role/MediaConvert_Default_Role",
"Settings": {
"TimecodeConfig": {
"Anchor": "00:00:00:00",
"Source": "EMBEDDED"
},
"OutputGroups": [
{
"Name": "File Group",
"Outputs": [
{
"Preset": "createPromoVideo",
"Extension": "mp4",
"NameModifier": "_fade",
"VideoDescription": {
"CodecSettings": {
"FilterGraph": "fade=out:150:30"
},
"ScalingBehavior": "DEFAULT",
"TimecodeInsertion": "DISABLED",
"AntiAlias": "ENABLED",
"Sharpness": 50,
"Height": 1080,
"Width": 1080
},
"AudioDescriptions": [
{
"AudioSelector": {
"SelectorSettings": [
{
"AudioSelectorName": "Default"
}
]
},
"CodecSettings": {
"Codec": "AAC",
"AacSettings": {
"Bitrate": 96000,
"CodingMode": "CODING_MODE_2_0",
"SampleRate": 48000
}
}
}
]
}
],
"OutputGroupSettings": {
"Type": "FILE_GROUP_SETTINGS",
"FileGroupSettings": {
"Destination": "s3://t44-post-cover/8fui.mp4",
"DestinationSettings": {
"S3Settings": {
"AccessControl": {
"CannedAcl": "PUBLIC_READ"
}
}
}
}
}
}
],
"Inputs": [
{
"FileInput": "s3://t44-post-cover/8fui",
"VideoSelector": {
"ColorSpace": "FOLLOW"
},
"FilterEnable": "AUTO",
"TimecodeSource": "ZEROBASED",
"InputClippings": [
{
"StartTimecode": "00:00:00:00",
"EndTimecode": "00:00:02:00"
}
],
"FilterGraph": "fade=in:0:30",
"AudioSelectors": {
"Default": {
"DefaultSelection": "DEFAULT"
}
}
}
]
},
"AccelerationSettings": {
"Mode": "DISABLED"
},
"StatusUpdateInterval": "SECONDS_60",
"Priority": 0
}
}
AWS MediaConvert requires you to have at least one Audio Selector.
Just provide it with this simple one:
"Inputs": [
...
{
"AudioSelectors": {
"Audio Selector 1": {
"Offset": 0,
"DefaultSelection": "DEFAULT",
"SelectorType": "LANGUAGE_CODE",
"ProgramSelection": 1,
"LanguageCode": "ENM"
}
},
...
},
UPDATE:
A more barebones one:
"Inputs": [
...
{
"AudioSelectors": {
"Audio Selector 1": {
DefaultSelection: 'DEFAULT',
},
}
},
...
},

icCube gauge with multiple band colors

I'm trying to make a gauge and want to have two band colors (wrong/red, good/green). I've an example of the amchart in their online Chart maker https://live.amcharts.com/new/edit/. But I'm not able to get this working in icCube.
current we have icCube reporting version 7.0.0 (5549).
This is my chart JSON:
{
"box": {
"id": "wb695",
"widgetAdapterId": "w28",
"rectangle": {
"left": 1510,
"top": 340,
"right": 1910,
"bottom": 640
},
"zIndex": 901
},
"data": {
"mode": "MDX",
"schemaSettings": {
"cubeName": null,
"schemaName": null
},
"options": {
"WIZARD": {
"measures": [],
"rows": [],
"rowsNonEmpty": false,
"columns": [],
"columnsNonEmpty": false,
"filter": []
},
"MDX": {
"statement": "with \n member [Measures].[Measure1] AS 0.9\n member [Measures].[Measure2] AS 0.1\nSELECT\n\n{[Measures].[Measure1], [Measures].[Measure2]} on 0\n\nFROM [cube]"
},
"DATASOURCE": {}
},
"ic3_name": "mdx Query-5",
"ic3_uid": "m17"
},
"data-render": {
"chartType": {
"label": "Gauge",
"proto": {
"chartPrototype": {
"type": "gauge",
"arrows": [
{
"id": "GaugeArrow-1"
}
],
"axes": [
{
"id": "GaugeAxis-1"
}
]
},
"graphPrototype": {},
"dataProviderType": 3
},
"id": "gauge-chart"
},
"graphsConfiguration": [
{
"graph": {}
}
],
"valueAxes": [],
"trendLinesGuides": {},
"configuredQuadrants": {},
"advanced": {
"titles": [],
"faceAlpha": 0,
"faceBorderAlpha": 0
},
"balloon": {
"offsetX": 8
},
"chartOptions": {
"axes": [
{
"axisAlpha": 0.25,
"bottomText": "SLA",
"bottomTextColor": "#2A3F56",
"tickAlpha": 0.25,
"bandOutlineAlpha": 1,
"bandAlpha": 1,
"bandOutlineThickness": 95,
"bandOutlineColor": "#0095BC",
"id": 1
}
],
"bands": [
{
"alpha": 0.8,
"color": "#B53728",
"endValue": 0.6,
"startValue": 0,
"id": "GaugeBand-1"
},
{
"alpha": 0.6,
"color": "#435035",
"endValue": 1,
"startValue": 0.6,
"innerRadius": 0.69,
"id": "GaugeBand-2"
}
]
},
"ic3Data": {
"chartTypeConfig": {
"pie-chart-donut": {
"chartType": {
"label": "Donut",
"proto": {
"chartPrototype": {
"type": "donut",
"pullOutRadius": 0,
"startDuration": 0,
"legend": {
"enabled": false,
"align": "center",
"markerType": "circle"
},
"innerRadius": "60%"
},
"dataProviderType": 1
},
"id": "pie-chart-donut"
},
"graphsConfiguration": [
{}
],
"valueAxes": [],
"trendLinesGuides": {},
"configuredQuadrants": {},
"advanced": {
"titles": []
},
"balloon": {
"offsetX": 8
},
"chartOptions": {
"showZeroSlices": false,
"labelsEnabled": false,
"innerRadius": "60%",
"startAngle": 270,
"radius": "",
"fontSize": 20,
"color": "#0095BC",
"outlineAlpha": 0.25,
"tapToActivate": false
}
}
}
},
"axes": [
{
"startValue": 0,
"endValue": 1,
"startAngle": -90,
"endAngle": 90
}
],
"valueFormatting": ""
},
"navigation": {
"menuVisibility": {
"back": true,
"axisXChange": "All",
"axisYChange": "All",
"filter": "All",
"reset": true,
"widget": true,
"others": "All"
},
"selectionMode": "disabled"
},
"events": {},
"filtering": {},
"hooks": {}
}
Sorry for the late answer, out of the box it's not possible but you can use hooks to change the javascript options sent to amcharts.
JS / On Widget Options :
function(context, options, $box) {
const bands = [
{
"color": "#00CC00",
"endValue": 300000,
"id": "GaugeBand-1",
"startValue": 0
},
{
"color": "#ffac29",
"endValue": 600000,
"id": "GaugeBand-2",
"startValue": 300000
},
{
"color": "#ea3838",
"endValue": 900000,
"id": "GaugeBand-3",
"innerRadius": "95%",
"startValue": 600000
}
];
options.axes[0]["bands"] = bands;
return options;
}
This should work

using mongodb case insentive regex with case insentive index

is mongo regex ignoring my index? I have a case insentive index, but by the look of things my regex search recognize it and ignores it.
db.getCollection("myCol").find({ value: /^mysearchVal/i }}).explain(...)
I have 95, 708 docs total.
output:
{
"queryPlanner": {
"plannerVersion": 1,
"namespace": "myDb.myCol",
"indexFilterSet": false,
"parsedQuery": {
"Value": {
"$regex": "^mysearchVal",
"$options": "i"
}
},
"winningPlan": {
"stage": "FETCH",
"filter": {
"Value": {
"$regex": "^mysearchVal",
"$options": "i"
}
},
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"Value": 1
},
"indexName": "value_case_insensitive_and_unique",
"collation": {
"locale": "en",
"caseLevel": false,
"caseFirst": "off",
"strength": 2,
"numericOrdering": false,
"alternate": "non-ignorable",
"maxVariable": "punct",
"normalization": false,
"backwards": false,
"version": "57.1"
},
"isMultiKey": false,
"multiKeyPaths": {
"Value": []
},
"isUnique": true,
"isSparse": false,
"isPartial": false,
"indexVersion": 2,
"direction": "forward",
"indexBounds": {
"Value": [
"[\"\", {})",
"[/^mysearchVal/i, /^mysearchVal/i]"
]
}
}
},
"rejectedPlans": []
},
"executionStats": {
"executionSuccess": true,
"nReturned": 1,
"executionTimeMillis": 1447,
"totalKeysExamined": 95708,
"totalDocsExamined": 95708,
"executionStages": {
"stage": "FETCH",
"filter": {
"Value": {
"$regex": "^mysearchVal",
"$options": "i"
}
},
"nReturned": 1,
"executionTimeMillisEstimate": 1270,
"works": 95709,
"advanced": 1,
"needTime": 95707,
"needYield": 0,
"saveState": 785,
"restoreState": 785,
"isEOF": 1,
"invalidates": 0,
"docsExamined": 95708,
"alreadyHasObj": 0,
"inputStage": {
"stage": "IXSCAN",
"nReturned": 95708,
"executionTimeMillisEstimate": 596,
"works": 95709,
"advanced": 95708,
"needTime": 0,
"needYield": 0,
"saveState": 785,
"restoreState": 785,
"isEOF": 1,
"invalidates": 0,
"keyPattern": {
"Value": 1
},
"indexName": "value_case_insensitive_and_unique",
"collation": {
"locale": "en",
"caseLevel": false,
"caseFirst": "off",
"strength": 2,
"numericOrdering": false,
"alternate": "non-ignorable",
"maxVariable": "punct",
"normalization": false,
"backwards": false,
"version": "57.1"
},
"isMultiKey": false,
"multiKeyPaths": {
"Value": []
},
"isUnique": true,
"isSparse": false,
"isPartial": false,
"indexVersion": 2,
"direction": "forward",
"indexBounds": {
"Value": [
"[\"\", {})",
"[/^mysearchVal/i, /^mysearchVal/i]"
]
},
"keysExamined": 95708,
"seeks": 1,
"dupsTested": 0,
"dupsDropped": 0,
"seenInvalidated": 0
}
},
"allPlansExecution": []
},
"ok": 1.0
}
the output shows 95,708 keys and docs examined, 1 doc returned. really? did the index apply in this case or am I missing a point or two?
Case insensitive regular expression queries generally cannot use
indexes effectively. The $regex implementation is not collation-aware
and is unable to utilize case-insensitive indexes.
https://docs.mongodb.com/manual/reference/operator/query/regex/#index-use

facebook reactions to be grouped by aggs terms elasticsearch

I am working on Facebook analytic, Here is a query which is supposed to fetch the summary of the reactions from Facebook page posts,
Note: posts json is as it is inserted to elastic-search db
{
"query": {
"match": {
"from.id": "[Page-id]"
}
},
"aggs": {
"summary_reaction": {
"terms": {
"field": "reactions.data.type.keyword"
}
}
}
}
Only issue is query return unique count whereas it should consider all reactions.
My result is
"aggregations": {
"reaction_summary": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "LIKE",
"doc_count": 2
},
{
"key": "HAHA",
"doc_count": 1
}
]
}
}
here is the sample json
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 6.158189,
"hits": [
{
"_index": "facebook_page",
"_type": "post",
"_id": "AV1RMRKSSM3OTvGpqzx7",
"_score": 6.158189,
"_source": {
"reactions": {
"paging": {
"cursors": {
"after": "TVRFMk9EYzVOekl5TWpjMU5USTJPakUxTURBek1EVTNOREU2TWpVME1EazJNVFl4TXc9PQZDZD",
"before": "TVRFMk9EYzVOekl5TWpjMU5USTJPakUxTURBek1EVTNOREU2TWpVME1EazJNVFl4TXc9PQZDZD"
}
},
"data": [
{
"pic_large": "https://fb-s-d-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p200x200/20108099_116879808942184_8792637908147052517_n.png?oh=4dcc9a9bbdfc965eb477a14775f31448&oe=5A0BCFB5&__gda__=1510661157_f329dd30b13490dbae8d05d3aa45d79f",
"type": "LIKE",
"id": "116879722275526",
"name": "Moojaa"
}
]
},
"from": {
"picture": {
"data": {
"url": "https://fb-s-d-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p50x50/20108099_116879808942184_8792637908147052517_n.png?oh=24cc256b24e5da70f306afcf784a636d&oe=59FBA1D4&__gda__=1509895651_44acee6189c7c1cb6eed023a6e742d1a",
"is_silhouette": false
}
},
"name": "Moojaa",
"id": "116879722275526"
},
"coordinates": {},
"created_time": "2017-07-17T15:35:35+0000",
"message": "Kuthey e Moojaa",
"type": "status",
"id": "116879722275526_116886608941504"
}
},
{
"_index": "facebook_page",
"_type": "post",
"_id": "AV1RMRViSM3OTvGpqzx8",
"_score": 6.158189,
"_source": {
"reactions": {
"paging": {
"cursors": {
"after": "TVRFMk9EYzVOekl5TWpjMU5USTJPakUxTURBek1EUTBNRGc2TWpVME1EazJNVFl4TXc9PQZDZD",
"before": "TVRBd01ERTFOREl5TkRrNE56Y3dPakUxTURBek1EUTFNams2TWpVME1EazJNVFl4TXc9PQZDZD"
}
},
"data": [
{
"pic_large": "https://fb-s-a-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p200x200/16864759_114731265717623_8811777667276972672_n.jpg?oh=836c6d5145bc8023d3ac60e0dfd42bde&oe=5A00D0DC&__gda__=1509885772_ad8923f4369250c2c2051c5e9293331f",
"type": "LIKE",
"id": "111467022710714",
"name": "Ram Singh Shankar"
},
{
"pic_large": "https://fb-s-d-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p200x200/20108099_116879808942184_8792637908147052517_n.png?oh=4dcc9a9bbdfc965eb477a14775f31448&oe=5A0BCFB5&__gda__=1510661157_f329dd30b13490dbae8d05d3aa45d79f",
"type": "LIKE",
"id": "116879722275526",
"name": "Moojaa"
}
]
},
"from": {
"picture": {
"data": {
"url": "https://fb-s-d-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p50x50/20108099_116879808942184_8792637908147052517_n.png?oh=24cc256b24e5da70f306afcf784a636d&oe=59FBA1D4&__gda__=1509895651_44acee6189c7c1cb6eed023a6e742d1a",
"is_silhouette": false
}
},
"name": "Moojaa",
"id": "116879722275526"
},
"coordinates": {},
"comments": {
"paging": {
"cursors": {
"after": "WTI5dGJXVnVkRjlqZAFhKemIzSTZANVEUyT0RneE5UUTRPVFF5TURFd09qRTFNREF6TURRMk5Eaz0ZD",
"before": "WTI5dGJXVnVkRjlqZAFhKemIzSTZANVEUyT0RneE5EUXlNamMxTXpVME9qRTFNREF6TURRMk1URT0ZD"
}
},
"data": [
{
"message": "test",
"from": {
"picture": {
"data": {
"url": "https://fb-s-a-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p200x200/16864759_114731265717623_8811777667276972672_n.jpg?oh=836c6d5145bc8023d3ac60e0dfd42bde&oe=5A00D0DC&__gda__=1509885772_ad8923f4369250c2c2051c5e9293331f",
"is_silhouette": false
}
},
"name": "Ram Singh Shankar",
"id": "111467022710714"
},
"id": "116880885608743_116881442275354"
},
{
"message": "test 2",
"from": {
"picture": {
"data": {
"url": "https://fb-s-a-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p200x200/16864759_114731265717623_8811777667276972672_n.jpg?oh=836c6d5145bc8023d3ac60e0dfd42bde&oe=5A00D0DC&__gda__=1509885772_ad8923f4369250c2c2051c5e9293331f",
"is_silhouette": false
}
},
"name": "Ram Singh Shankar",
"id": "111467022710714"
},
"id": "116880885608743_116881548942010"
}
]
},
"created_time": "2017-07-17T15:13:23+0000",
"message": "another Mooja",
"type": "status",
"id": "116879722275526_116880885608743"
}
},
{
"_index": "facebook_page",
"_type": "post",
"_id": "AV1RMRgtSM3OTvGpqzx9",
"_score": 6.158189,
"_source": {
"reactions": {
"paging": {
"cursors": {
"after": "TVRBd01ERTFOREl5TkRrNE56Y3dPakUxTURBek1EUXpPRGM2TnpnNE5qUTRNRE0zT1RFek16RXkZD",
"before": "TVRFMk9EYzVOekl5TWpjMU5USTJPakUxTURBek1EUTVOVEk2TnpnNE5qUTRNRE0zT1RFek16RXkZD"
}
},
"data": [
{
"pic_large": "https://fb-s-d-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p200x200/20108099_116879808942184_8792637908147052517_n.png?oh=4dcc9a9bbdfc965eb477a14775f31448&oe=5A0BCFB5&__gda__=1510661157_f329dd30b13490dbae8d05d3aa45d79f",
"type": "HAHA",
"id": "116879722275526",
"name": "Moojaa"
},
{
"pic_large": "https://fb-s-a-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p200x200/16864759_114731265717623_8811777667276972672_n.jpg?oh=836c6d5145bc8023d3ac60e0dfd42bde&oe=5A00D0DC&__gda__=1509885772_ad8923f4369250c2c2051c5e9293331f",
"type": "HAHA",
"id": "111467022710714",
"name": "Ram Singh Shankar"
}
]
},
"from": {
"picture": {
"data": {
"url": "https://fb-s-d-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p50x50/20108099_116879808942184_8792637908147052517_n.png?oh=24cc256b24e5da70f306afcf784a636d&oe=59FBA1D4&__gda__=1509895651_44acee6189c7c1cb6eed023a6e742d1a",
"is_silhouette": false
}
},
"name": "Moojaa",
"id": "116879722275526"
},
"coordinates": {},
"comments": {
"paging": {
"cursors": {
"after": "WTI5dGJXVnVkRjlqZAFhKemIzSTZANVEUyT0RneE9ESTFOakE0TmpRNU9qRTFNREF6TURRM05EYz0ZD",
"before": "WTI5dGJXVnVkRjlqZAFhKemIzSTZANVEUyT0RneE5UVTRPVFF5TURBNU9qRTFNREF6TURRMk5UUT0ZD"
}
},
"data": [
{
"message": "test 3",
"from": {
"picture": {
"data": {
"url": "https://fb-s-d-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p200x200/20108099_116879808942184_8792637908147052517_n.png?oh=4dcc9a9bbdfc965eb477a14775f31448&oe=5A0BCFB5&__gda__=1510661157_f329dd30b13490dbae8d05d3aa45d79f",
"is_silhouette": false
}
},
"name": "Moojaa",
"id": "116879722275526"
},
"id": "116880192275479_116881558942009"
},
{
"message": "test ram",
"from": {
"picture": {
"data": {
"url": "https://fb-s-a-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p200x200/16864759_114731265717623_8811777667276972672_n.jpg?oh=836c6d5145bc8023d3ac60e0dfd42bde&oe=5A00D0DC&__gda__=1509885772_ad8923f4369250c2c2051c5e9293331f",
"is_silhouette": false
}
},
"name": "Ram Singh Shankar",
"id": "111467022710714"
},
"id": "116880192275479_116881578942007"
},
{
"message": "test singh",
"from": {
"picture": {
"data": {
"url": "https://fb-s-a-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p200x200/16864759_114731265717623_8811777667276972672_n.jpg?oh=836c6d5145bc8023d3ac60e0dfd42bde&oe=5A00D0DC&__gda__=1509885772_ad8923f4369250c2c2051c5e9293331f",
"is_silhouette": false
}
},
"name": "Ram Singh Shankar",
"id": "111467022710714"
},
"id": "116880192275479_116881598942005"
},
{
"message": "khair",
"from": {
"picture": {
"data": {
"url": "https://fb-s-d-a.akamaihd.net/h-ak-fbx/v/t1.0-1/p200x200/20108099_116879808942184_8792637908147052517_n.png?oh=4dcc9a9bbdfc965eb477a14775f31448&oe=5A0BCFB5&__gda__=1510661157_f329dd30b13490dbae8d05d3aa45d79f",
"is_silhouette": false
}
},
"name": "Moojaa",
"id": "116879722275526"
},
"id": "116880192275479_116881825608649"
}
]
},
"created_time": "2017-07-17T15:10:12+0000",
"message": "Testing my Mooja",
"type": "status",
"id": "116879722275526_116880192275479"
}
}
]
}
}
You have to set data inside the reactions as nested type and you can do nested aggregation on the data to get all the counts for the type.
Mappings
PUT facebook_index1
{
"mappings": {
"document_type" : {
"properties": {
"reactions" : {
"type": "object",
"properties": {
"data" : {
"type" : "nested",
"properties" : {
"type" : {
"type" : "keyword"
}
}
}
}
}
}
}
}
}
Query
use nested aggs to aggregate for type for data.
POST facebook_index1/_search
{
"size": 0,
"aggs": {
"nested_data_aggs": {
"nested": {
"path": "reactions.data"
},
"aggs": {
"summary_reaction": {
"terms": {
"field": "reactions.data.type",
"size": 10
}
}
}
}
}
}
Hope this works

Hypen in response data is throwing error when setting as global variable for nested response

I have a post man request. Which returns a response data as:
[
{
"id": "7ca27c09-2b67-417e-b367-f97d49824a2f",
"tags": [],
"type": "ApplicationProfile",
"userId": "2f2c8684-874d-49ea-bfa4-977069c1e3e2",
"profile": {
"User-Profile": {
"PHI": {
"gender": "Male",
"surgeryDate": {
"value": "2017-06-06"
},
"surgeryType": {
"value": "gastricBand"
},
"heightInches": "72",
"approvalPhase": "2",
"profileImageUrl": "",
"motivationalImageUrl": ""
},
"PII": {
"mail": "c11#c111.com",
"lastName": "",
"firstName": "name1",
"shouldReceiveNotifications": true
}
},
"motivationalGoals": [
{
"goal": "Improving health",
"goalId": "2957"
},
{
"goal": "Relieving pain",
"goalId": "2958"
},
{
"goal": "Feeling better",
"goalId": "2960"
}
]
},
"version": 35,
"createdBy": "2f2c8684-874d-49ea-bfa4-977069c1e3e2",
"lastModifiedBy": "2f2c8684-874d-49ea-bfa4-977069c1e3e2",
"applicationName": "Health Partner",
"createdDateTime": "2017-06-08T16:08:32.497Z",
"lastModifiedDateTime": "2017-06-09T13:23:03.503Z"
},
{
"id": "091b5ebd-b096-436e-a703-f97f0ae77baf",
"tags": [
"Application-Profile"
],
"type": "ApplicationProfile",
"userId": "2f2c8684-874d-49ea-bfa4-977069c1e3e2",
"profile": {
"User-Profile": {
"PHI": {
"gender": "",
"surgeryDate": {
"value": "2017-06-01"
},
"surgeryType": {
"value": ""
},
"heightInches": "72",
"approvalPhase": "2",
"profileImageUrl": "",
"motivationalImageUrl": ""
},
"PII": {
"mail": "c11#c111.com",
"lastName": "Dev",
"firstName": "Kat",
"shouldReceiveNotifications": true
}
},
"motivationalGoals": [
{
"goal": "Improving health",
"goalId": "2957"
},
{
"goal": "Relieving pain",
"goalId": "2958"
},
{
"goal": "Feeling better",
"goalId": "2960"
}
]
},
"version": 41,
"createdBy": "2f2c8684-874d-49ea-bfa4-977069c1e3e2",
"lastModifiedBy": "2f2c8684-874d-49ea-bfa4-977069c1e3e2",
"applicationName": "Health Partner Weightloss",
"createdDateTime": "2017-06-03T16:19:57.811Z",
"lastModifiedDateTime": "2017-06-08T16:07:49.555Z"
}
]
I need to extract the value of the emailid and set as global variable.
here is my code:
var jsonData1 = JSON.parse(responseBody);
postman.setGlobalVariable("jsonData1",jsonData1.profile.User-Profile.PII.mail);
But I am getting error. "User is undefined".
The problem here is that the hyphen / minus sign is interpreted as the subtraction operator.
Consider changing your API and using "userProfile" instead of "User-Profile".