can anyone help ?
the query is run successfully as the separated "match query" and "range query" , but i get error when run this
this is my query but i cant get the result :
GET composition_value/composition/_count
{
"query": {
"nested": {
"path": "value",
"query": {
"match": {
"value.composition.content.data.events.data.items.name.value": "systolic"
},
"range": {
"value.composition.content.data.events.data.items.value.magnitude": {
"gte": 10,
"lte": 99
}
}
}
}
}
}
here is the error , result of the query:
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "[match] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
"line": 10,
"col": 9
}
],
"type": "parsing_exception",
"reason": "[match] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
"line": 10,
"col": 9
},
"status": 400
}
Edited
the problem is i want just "magnitude" filed in "systolic" not other
Here is the main Document i search on it:
{
"composition": {
"name": {
"value": "Avaexample1"
},
"archetype_details": {
"archetype_id": {
"value": "openEHR-EHR-COMPOSITION.avaexample1.v0"
},
"template_id": {
"value": "New Template"
},
"rm_version": "1.0.2"
},
"language": {
"terminology_id": {
"value": "ISO_639-1"
},
"code_string": "en"
},
"territory": {
"terminology_id": {
"value": "ISO_3166-1"
},
"code_string": "UY"
},
"category": {
"value": "event",
"defining_code": {
"terminology_id": {
"value": "openehr"
},
"code_string": "433"
}
},
"composer": {
"external_ref": {
"id": {
"value": "ecd01eaf-775a-43c9-8b4b-1a9ba0257568",
"_xsi:type": "HIER_OBJECT_ID"
},
"namespace": "DEMOGRAPHIC",
"type": "PERSON"
},
"name": "Dr. Yamamoto",
"_xsi:type": "PARTY_IDENTIFIED"
},
"context": {
"start_time": {
"value": "20170723T122153,184+0430"
},
"setting": {
"value": "Hospital B",
"defining_code": {
"terminology_id": {
"value": "openehr"
},
"code_string": "229"
}
}
},
"content": {
"name": {
"value": "Blood pressure"
},
"language": {
"terminology_id": {
"value": "ISO_639-1"
},
"code_string": "en"
},
"encoding": {
"terminology_id": {
"value": "Unicode"
},
"code_string": "UTF-8"
},
"subject": {
"_xsi:type": "PARTY_SELF"
},
"protocol": {
"name": {
"value": "list structure"
},
"items": [{
"name": {
"value": "Cuff size"
},
"value": {
"value": "Adult Thigh",
"defining_code": {
"terminology_id": {
"value": "local"
},
"code_string": "at0015"
},
"_xsi:type": "DV_CODED_TEXT"
},
"_archetype_node_id": "at0013",
"_xsi:type": "ELEMENT"
},
{
"name": {
"value": "Location"
},
"items": [{
"name": {
"value": "Non-invasive locations"
},
"value": {
"value": "Right arm",
"defining_code": {
"terminology_id": {
"value": "local"
},
"code_string": "at0025"
},
"_xsi:type": "DV_CODED_TEXT"
},
"_archetype_node_id": "at0014.1",
"_xsi:type": "ELEMENT"
},
{
"name": {
"value": "Intra-arterial locations"
},
"value": {
"value": "Radial Left",
"defining_code": {
"terminology_id": {
"value": "local"
},
"code_string": "at0.1059"
},
"_xsi:type": "DV_CODED_TEXT"
},
"_archetype_node_id": "at0.1058",
"_xsi:type": "ELEMENT"
},
{
"name": {
"value": "Specific location"
},
"value": {
"value": "UzuefCsHBYVwKK,WzicypjaKpjqHAw",
"defining_code": {
"terminology_id": {
"value": "terminology_not_specified_as_constraint_or_referenceSetUri_in_opt"
},
"code_string": "1002779"
},
"_xsi:type": "DV_CODED_TEXT"
},
"_archetype_node_id": "at1034",
"_xsi:type": "ELEMENT"
}],
"_archetype_node_id": "at1033",
"_xsi:type": "CLUSTER"
},
{
"name": {
"value": "Method"
},
"value": {
"value": "Auscultation",
"defining_code": {
"terminology_id": {
"value": "local"
},
"code_string": "at1036"
},
"_xsi:type": "DV_CODED_TEXT"
},
"_archetype_node_id": "at1035",
"_xsi:type": "ELEMENT"
},
{
"name": {
"value": "Mean Arterial Pressure Formula"
},
"value": {
"value": "jErCuglJdkV,KjmPwC.xxwoGTikkIprmZwVyTrfZIrm WCzMcIaQG MkLOeqjFbDVJxQZYLWyZgiIszVuyytmxdOIFsdPTxyz jct.SqjOedXuxSl REmuIrUnpMuqgIZaZIapQVHDoPvnQSivESJPTOptqDxAxwVpTJKIAL ldtMyUOWj,ym,AYZTzJugWFhLOdkJXhTFewmHSRBFwKEouqMVPgbnmrTzfLNoncDDgpuBPCrdyojWM.UMKuqe",
"_xsi:type": "DV_TEXT"
},
"_archetype_node_id": "at1038",
"_xsi:type": "ELEMENT"
},
{
"name": {
"value": "Diastolic endpoint"
},
"value": {
"value": "Phase IV",
"defining_code": {
"terminology_id": {
"value": "local"
},
"code_string": "at1011"
},
"_xsi:type": "DV_CODED_TEXT"
},
"_archetype_node_id": "at1010",
"_xsi:type": "ELEMENT"
},
{
"name": {
"value": "Suitable for graphing?"
},
"value": {
"value": "true",
"_xsi:type": "DV_BOOLEAN"
},
"_archetype_node_id": "at0.1054",
"_xsi:type": "ELEMENT"
}],
"_archetype_node_id": "at0011",
"_xsi:type": "ITEM_TREE"
},
"data": {
"name": {
"value": "history"
},
"origin": {
"value": "20170723T122153,605+0430",
"_xsi:type": "DV_DATE_TIME"
},
"events": {
"name": {
"value": "any event"
},
"time": {
"value": "20170723T122153,621+0430",
"_xsi:type": "DV_DATE_TIME"
},
"data": {
"name": {
"value": "blood pressure"
},
"items": [{
"name": {
"value": "Systolic"
},
"value": {
"magnitude": "70",
"units": "cm[Hg]",
"_xsi:type": "DV_QUANTITY"
},
"_archetype_node_id": "at0004",
"_xsi:type": "ELEMENT"
},
{
"name": {
"value": "Diastolic"
},
"value": {
"magnitude": "80",
"units": "cm[Hg]",
"_xsi:type": "DV_QUANTITY"
},
"_archetype_node_id": "at0005",
"_xsi:type": "ELEMENT"
},
{
"name": {
"value": "Mean Arterial Pressure"
},
"value": {
"magnitude": "615",
"units": "mm[Hg]",
"_xsi:type": "DV_QUANTITY"
},
"_archetype_node_id": "at1006",
"_xsi:type": "ELEMENT"
},
{
"name": {
"value": "Pulse Pressure"
},
"value": {
"magnitude": "324",
"units": "mm[Hg]",
"_xsi:type": "DV_QUANTITY"
},
"_archetype_node_id": "at1007",
"_xsi:type": "ELEMENT"
},
{
"name": {
"value": "Comment"
},
"value": {
"value": "QppbwmXaKavNSNXmIpkSADyBZ,eFLKjwUomBscVAPHzWQLNTMkvcokamY,NFbcrmLNAlxn.hmpTHRjRNNcIhwfQJUpBpzVohQvoukpZb.ezPmOCcHQNVTcmHeMVShPvMtMFeSXrMeHZstnmikelrCWGMGDEwBKvAabKWDDotsfbMGpETL oifeUyxUxOGFmhwwgDkAjifomZXm.yCIEitsahimjwLwyZyXyOqrJnqcyhNvbhwUwUQtTqeOUiTtm",
"_xsi:type": "DV_TEXT"
},
"_archetype_node_id": "at0033",
"_xsi:type": "ELEMENT"
}],
"_archetype_node_id": "at0003",
"_xsi:type": "ITEM_TREE"
},
"state": {
"name": {
"value": "state structure"
},
"items": [{
"name": {
"value": "Position"
},
"value": {
"value": "Standing",
"defining_code": {
"terminology_id": {
"value": "local"
},
"code_string": "at1000"
},
"_xsi:type": "DV_CODED_TEXT"
},
"_archetype_node_id": "at0008",
"_xsi:type": "ELEMENT"
},
{
"name": {
"value": "Confounding factors"
},
"value": {
"value": ",dUW hFmdIEDsQN ifxzaVoIUXcwrI,bRnmIWpd udD,,HWqrLzDpaybOKgXWNNCZgjACXlKNUQCIXpWgMUWumXo oNWATIhPe BBb,GxdciYgTfMEpeHtiuV,DfESmNFOxWANjyskrgWhANaViKHcSyHfUVdPiTfFi.,XPSrJamSCfUrOYHBO,axGQenCnGrdFEHlPNxc RwzAUzjwRdNAdOqVAYmFoVkPLlhjgajECMYXfoTqrYKtTP.BiIpo",
"_xsi:type": "DV_TEXT"
},
"_archetype_node_id": "at1052",
"_xsi:type": "ELEMENT"
},
{
"name": {
"value": "Sleep status"
},
"value": {
"value": "Alert & awake",
"defining_code": {
"terminology_id": {
"value": "local"
},
"code_string": "at1044"
},
"_xsi:type": "DV_CODED_TEXT"
},
"_archetype_node_id": "at1043",
"_xsi:type": "ELEMENT"
},
{
"name": {
"value": "Tilt"
},
"value": {
"magnitude": "-72",
"units": "",
"_xsi:type": "DV_QUANTITY"
},
"_archetype_node_id": "at1005",
"_xsi:type": "ELEMENT"
}],
"_archetype_node_id": "at0007",
"_xsi:type": "ITEM_TREE"
},
"_archetype_node_id": "at0006",
"_xsi:type": "POINT_EVENT"
},
"_archetype_node_id": "at0001",
"_xsi:type": "HISTORY"
},
"_archetype_node_id": "openEHR-EHR-OBSERVATION.blood_pressure-zn.v1",
"_xsi:type": "OBSERVATION"
},
"_xmlns": "http://schemas.openehr.org/v1",
"_xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"_archetype_node_id": "openEHR-EHR-COMPOSITION.avaexample1.v0"
}
}
As described here, try this:
{
"query": {
"nested": {
"path": "value",
"query": {
"bool": {
"must": [
{
"match": {
"value.composition.content.data.events.data.items.name.value": "systolic"
}
},
{
"range": {
"value.composition.content.data.events.data.items.value.magnitude": {
"gte": 10,
"lte": 99
}
}
}
]
}
}
}
}
}
Related
I am creating logicapp expression in which I need to substitute variable within the expression.
What what I want to achieve is : something like this
#{body('actionName')?['parentName1']?['2022-10-14:14']?['142.0'][0]?['ask']}
in the above expression, variable1 & variable2 holds 2022-10-14:14 & 142.0 respectively.
to achieve this, I am trying this below which is giving me null values
Trail-1:
#{body('actionName')?['parent1']?['#variables('dateVariable')']?['#variables('priceVariable')'][0]?['ask']}
Trail-2:
#{body('actionName')?['parent1']?['#variables("dateVariable")']?['#variables("priceVariable")'][0]?['ask']}
Trail-3:
#{body('actionName')?['parent1']?["#variables('dateVariable')"]?["#variables('priceVariable')"][0]?['ask']}
None of these trails worked, please let me know if you have any clue, many thanks in advance.
You need to remove your quotes.
Load this example into you tenant and it will show you a working example.
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Initialize_AUD_Property_Name": {
"inputs": {
"variables": [
{
"name": "AUD Property Name",
"type": "string",
"value": "AUD"
}
]
},
"runAfter": {
"Initialize_Currencies_Property_Name": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_Currencies_Property_Name": {
"inputs": {
"variables": [
{
"name": "Currencies Property Name",
"type": "string",
"value": "Currencies"
}
]
},
"runAfter": {
"Initialize_JSON_Object": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_JSON_Object": {
"inputs": {
"variables": [
{
"name": "JSON Object",
"type": "object",
"value": {
"altSpellings": [
"AU"
],
"area": 7692024,
"capital": [
"Canberra"
],
"capitalInfo": {
"latlng": [
-35.27,
149.13
]
},
"car": {
"side": "left",
"signs": [
"AUS"
]
},
"cca2": "AU",
"cca3": "AUS",
"ccn3": "036",
"cioc": "AUS",
"coatOfArms": {
"png": "https://mainfacts.com/media/images/coats_of_arms/au.png",
"svg": "https://mainfacts.com/media/images/coats_of_arms/au.svg"
},
"continents": [
"Oceania"
],
"currencies": {
"AUD": {
"name": "Australian dollar",
"symbol": "$"
}
},
"demonyms": {
"eng": {
"f": "Australian",
"m": "Australian"
},
"fra": {
"f": "Australienne",
"m": "Australien"
}
},
"fifa": "AUS",
"flag": "🇦🇺",
"flags": {
"png": "https://flagcdn.com/w320/au.png",
"svg": "https://flagcdn.com/au.svg"
},
"gini": {
"2014": 34.4
},
"idd": {
"root": "+6",
"suffixes": [
"1"
]
},
"independent": true,
"landlocked": false,
"languages": {
"eng": "English"
},
"latlng": [
-27,
133
],
"maps": {
"googleMaps": "https://goo.gl/maps/DcjaDa7UbhnZTndH6",
"openStreetMaps": "https://www.openstreetmap.org/relation/80500"
},
"name": {
"common": "Australia",
"nativeName": {
"eng": {
"common": "Australia",
"official": "Commonwealth of Australia"
}
},
"official": "Commonwealth of Australia"
},
"population": 25687041,
"postalCode": {
"format": "####",
"regex": "^(\\d{4})$"
},
"region": "Oceania",
"startOfWeek": "monday",
"status": "officially-assigned",
"subregion": "Australia and New Zealand",
"timezones": [
"UTC+05:00",
"UTC+06:30",
"UTC+07:00",
"UTC+08:00",
"UTC+09:30",
"UTC+10:00",
"UTC+10:30",
"UTC+11:30"
],
"tld": [
".au"
],
"translations": {
"ara": {
"common": "أستراليا",
"official": "كومونولث أستراليا"
},
"bre": {
"common": "Aostralia",
"official": "Kenglad Aostralia"
},
"ces": {
"common": "Austrálie",
"official": "Australské společenství"
},
"cym": {
"common": "Awstralia",
"official": "Cymanwlad Awstralia"
},
"deu": {
"common": "Australien",
"official": "Commonwealth Australien"
},
"est": {
"common": "Austraalia",
"official": "Austraalia Ühendus"
},
"fin": {
"common": "Australia",
"official": "Australian liittovaltio"
},
"fra": {
"common": "Australie",
"official": "Australie"
},
"hrv": {
"common": "Australija",
"official": "Commonwealth of Australia"
},
"hun": {
"common": "Ausztrália",
"official": "Ausztrál Államszövetség"
},
"ita": {
"common": "Australia",
"official": "Commonwealth dell'Australia"
},
"jpn": {
"common": "オーストラリア",
"official": "オーストラリア連邦"
},
"kor": {
"common": "호주",
"official": "오스트레일리아 연방"
},
"nld": {
"common": "Australië",
"official": "Gemenebest van Australië"
},
"per": {
"common": "استرالیا",
"official": "قلمرو همسود استرالیا"
},
"pol": {
"common": "Australia",
"official": "Związek Australijski"
},
"por": {
"common": "Austrália",
"official": "Comunidade da Austrália"
},
"rus": {
"common": "Австралия",
"official": "Содружество Австралии"
},
"slk": {
"common": "Austrália",
"official": "Austrálsky zväz"
},
"spa": {
"common": "Australia",
"official": "Mancomunidad de Australia"
},
"swe": {
"common": "Australien",
"official": "Australiska statsförbundet"
},
"tur": {
"common": "Avustralya",
"official": "Avustralya Federal Devleti"
},
"urd": {
"common": "آسٹریلیا",
"official": "دولتِ مشترکہ آسٹریلیا"
},
"zho": {
"common": "澳大利亚",
"official": "澳大利亚联邦"
}
},
"unMember": true
}
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Initialize_Name_Value": {
"inputs": {
"variables": [
{
"name": "Name Value",
"type": "string",
"value": "#{variables('JSON Object')?[variables('Currencies Property Name')]?[variables('AUD Property Name')]?['Name']}"
}
]
},
"runAfter": {
"Initialize_AUD_Property_Name": [
"Succeeded"
]
},
"type": "InitializeVariable"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"ParameterTest1": {
"defaultValue": "\"\"",
"type": "String"
}
},
"triggers": {
"manual": {
"inputs": {
"method": "GET",
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}
Buried within there is an example expression that uses the names of the properties from a variable to extract the value.
Said expression looks like this (as you can see, no quotes) ...
variables('JSON Object')?[variables('Currencies Property Name')]?[variables('AUD Property Name')]?['Name']
There is a document describing how to allocate a public IP per VM in VMSS: https://learn.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-networking#public-ipv4-per-virtual-machine
But it is not clear how to assign public static IP per VM. Is it possible?
Unfortunately, Azure does not provide control of the Public IP allocation method per instance in VMSS. You can see the all supported Properties of
VirtualMachineScaleSetPublicIPAddressConfigurationProperties object in the latest ARM API version.
However, after my validation, when you restart the instance or VMSS scale-in or scale-out, the public IP address of existing instances is not changed. The public IP address of instances will be updated unless you stop the instance of VMSS.
Update
Currently, you can manage it with IpPublicPrefix. Note that IpPublicPrefix requires a standard SKU load balancer and public IP address. Here is a working sample. You can check the public IP address of the instances in VMSS with the REST API.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmSku": {
"type": "string",
"defaultValue": "Standard_A1_v2",
"metadata": {
"description": "Size of VMs in the VM Scale Set."
}
},
"windowsOSVersion": {
"type": "string",
"defaultValue": "2019-Datacenter",
"allowedValues": [
"2008-R2-SP1",
"2012-Datacenter",
"2012-R2-Datacenter",
"2016-Datacenter",
"2019-Datacenter"
],
"metadata": {
"description": "The Windows version for the VM. This will pick a fully patched image of this given Windows version. Allowed values: 2008-R2-SP1, 2012-Datacenter, 2012-R2-Datacenter & 2016-Datacenter, 2019-Datacenter."
}
},
"vmssName": {
"type": "string",
"minLength": 3,
"maxLength": 61,
"metadata": {
"description": "String used as a base for naming resources. Must be 3-61 characters in length and globally unique across Azure. A hash is prepended to this string for some resources, and resource-specific information is appended."
}
},
"instanceCount": {
"type": "int",
"defaultValue": 3,
"minValue": 1,
"maxValue": 100,
"metadata": {
"description": "Number of VM instances (100 or less)."
}
},
"singlePlacementGroup": {
"type": "bool",
"defaultValue": true,
"metadata": {
"description": "When true this limits the scale set to a single placement group, of max size 100 virtual machines. NOTE: If singlePlacementGroup is true, it may be modified to false. However, if singlePlacementGroup is false, it may not be modified to true."
}
},
"adminUsername": {
"type": "string",
"defaultValue": "vmssadmin",
"metadata": {
"description": "Admin username on all VMs."
}
},
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "Admin password on all VMs."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
},
"platformFaultDomainCount": {
"type": "int",
"defaultValue": 1,
"metadata": {
"description": "Fault Domain count for each placement group."
}
},
"publicIPPrefixes_pubprefix_name": {
"defaultValue": "vmsspublicprefix",
"type": "string"
}
},
"variables": {
"namingInfix": "[toLower(substring(concat(parameters('vmssName'), uniqueString(resourceGroup().id)), 0, 9))]",
"longNamingInfix": "[toLower(parameters('vmssName'))]",
"addressPrefix": "10.0.0.0/16",
"subnetPrefix": "10.0.0.0/24",
"virtualNetworkName": "[concat(variables('namingInfix'), 'vnet')]",
"publicIPAddressName": "[concat(variables('namingInfix'), 'pip')]",
"subnetName": "[concat(variables('namingInfix'), 'subnet')]",
"loadBalancerName": "[concat(variables('namingInfix'), 'lb')]",
"publicIPAddressID": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]",
"lbProbeID": "[resourceId('Microsoft.Network/loadBalancers/probes',variables('loadBalancerName'), 'tcpProbe')]",
"natPoolName": "[concat(variables('namingInfix'), 'natpool')]",
"bePoolName": "[concat(variables('namingInfix'), 'bepool')]",
"lbPoolID": "[resourceId('Microsoft.Network/loadBalancers/backendAddressPools',variables('loadBalancerName'),variables('bePoolName'))]",
"natStartPort": 50000,
"natEndPort": 50119,
"natBackendPort": 3389,
"nicName": "[concat(variables('namingInfix'), 'nic')]",
"ipConfigName": "[concat(variables('namingInfix'), 'ipconfig')]",
"frontEndIPConfigID": "[resourceId('Microsoft.Network/loadBalancers/frontendIPConfigurations',variables('loadBalancerName'),'loadBalancerFrontEnd')]",
"osType": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "[parameters('windowsOSVersion')]",
"version": "latest"
},
"imageReference": "[variables('osType')]"
},
"resources": [
{
"type": "Microsoft.Network/loadBalancers",
"apiVersion": "2020-06-01",
"name": "[variables('loadBalancerName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))]"
],
"sku": {
"name": "Standard"
},
"properties": {
"frontendIPConfigurations": [
{
"name": "LoadBalancerFrontEnd",
"properties": {
"publicIPAddress": {
"id": "[variables('publicIPAddressID')]",
"name": "Standard"
}
}
}
],
"backendAddressPools": [
{
"name": "[variables('bePoolName')]"
}
],
"inboundNatPools": [
{
"name": "[variables('natPoolName')]",
"properties": {
"frontendIPConfiguration": {
"id": "[variables('frontEndIPConfigID')]"
},
"protocol": "Tcp",
"frontendPortRangeStart": "[variables('natStartPort')]",
"frontendPortRangeEnd": "[variables('natEndPort')]",
"backendPort": "[variables('natBackendPort')]"
}
}
],
"loadBalancingRules": [
{
"name": "LBRule",
"properties": {
"frontendIPConfiguration": {
"id": "[variables('frontEndIPConfigID')]"
},
"backendAddressPool": {
"id": "[variables('lbPoolID')]"
},
"protocol": "Tcp",
"frontendPort": 80,
"backendPort": 80,
"enableFloatingIP": false,
"idleTimeoutInMinutes": 5,
"probe": {
"id": "[variables('lbProbeID')]"
}
}
}
],
"probes": [
{
"name": "tcpProbe",
"properties": {
"protocol": "Tcp",
"port": 80,
"intervalInSeconds": 5,
"numberOfProbes": 2
}
}
]
}
},
{
"type": "Microsoft.Network/publicIPPrefixes",
"apiVersion": "2020-11-01",
"name": "[parameters('publicIPPrefixes_pubprefix_name')]",
"location": "[parameters('location')]",
"sku": {
"name": "Standard",
"tier": "Regional"
},
"properties": {
"prefixLength": 28,
"publicIPAddressVersion": "IPv4",
"ipTags": []
}
},
{
"type": "Microsoft.Compute/virtualMachineScaleSets",
"apiVersion": "2020-06-01",
"name": "[variables('namingInfix')]",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('vmSku')]",
"tier": "Standard",
"capacity": "[parameters('instanceCount')]"
},
"dependsOn": [
"[resourceId('Microsoft.Network/loadBalancers', variables('loadBalancerName'))]",
"[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]",
"[resourceId('Microsoft.Network/publicIPPrefixes',parameters('publicIPPrefixes_pubprefix_name'))]"
],
"properties": {
"overprovision": true,
"upgradePolicy": {
"mode": "Automatic"
},
"singlePlacementGroup": "[parameters('singlePlacementGroup')]",
"platformFaultDomainCount": "[parameters('platformFaultDomainCount')]",
"virtualMachineProfile": {
"storageProfile": {
"osDisk": {
"caching": "ReadWrite",
"createOption": "FromImage"
},
"imageReference": "[variables('imageReference')]"
},
"osProfile": {
"computerNamePrefix": "[variables('namingInfix')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"networkProfile": {
"networkInterfaceConfigurations": [
{
"name": "[variables('nicName')]",
"properties": {
"primary": true,
"ipConfigurations": [
{
"name": "[variables('ipConfigName')]",
"properties": {
"subnet": {
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnetName'))]"
},
"loadBalancerBackendAddressPools": [
{
"id": "[variables('lbPoolID')]"
}
],
"loadBalancerInboundNatPools": [
{
"id": "[resourceId('Microsoft.Network/loadBalancers/inboundNatPools', variables('loadBalancerName'), variables('natPoolName'))]"
}
],
"publicipaddressconfiguration": {
"name": "pub1",
"properties": {
"idleTimeoutInMinutes": 15,
"publicIPAddressVersion": "IPv4",
"publicIPPrefix":{
"id": "[resourceId('Microsoft.Network/publicIPPrefixes',parameters('publicIPPrefixes_pubprefix_name'))]"
}
}
}
}
}
]
}
}
]
}
}
}
},
{
"type": "Microsoft.Network/publicIPAddresses",
"apiVersion": "2020-06-01",
"name": "[variables('publicIPAddressName')]",
"location": "[parameters('location')]",
"sku": {
"name": "Standard"
},
"properties": {
"publicIPAllocationMethod": "Static",
"dnsSettings": {
"domainNameLabel": "[variables('longNamingInfix')]"
}
}
},
{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2020-06-01",
"name": "[variables('virtualNetworkName')]",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('addressPrefix')]"
]
},
"subnets": [
{
"name": "[variables('subnetName')]",
"properties": {
"addressPrefix": "[variables('subnetPrefix')]"
}
}
]
}
},
{
"type": "Microsoft.Insights/autoscaleSettings",
"apiVersion": "2015-04-01",
"name": "autoscalehost",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Compute/virtualMachineScaleSets/', variables('namingInfix'))]"
],
"properties": {
"name": "autoscalehost",
"targetResourceUri": "[resourceId('Microsoft.Compute/virtualMachineScaleSets', variables('namingInfix'))]",
"enabled": true,
"profiles": [
{
"name": "Profile1",
"capacity": {
"minimum": "1",
"maximum": "10",
"default": "1"
},
"rules": [
{
"metricTrigger": {
"metricName": "Percentage CPU",
"metricResourceUri": "[resourceId('Microsoft.Compute/virtualMachineScaleSets', variables('namingInfix'))]",
"timeGrain": "PT1M",
"statistic": "Average",
"timeWindow": "PT5M",
"timeAggregation": "Average",
"operator": "GreaterThan",
"threshold": 50
},
"scaleAction": {
"direction": "Increase",
"type": "ChangeCount",
"value": "1",
"cooldown": "PT5M"
}
},
{
"metricTrigger": {
"metricName": "Percentage CPU",
"metricResourceUri": "[resourceId('Microsoft.Compute/virtualMachineScaleSets', variables('namingInfix'))]",
"timeGrain": "PT1M",
"statistic": "Average",
"timeWindow": "PT5M",
"timeAggregation": "Average",
"operator": "LessThan",
"threshold": 30
},
"scaleAction": {
"direction": "Decrease",
"type": "ChangeCount",
"value": "1",
"cooldown": "PT5M"
}
}
]
}
]
}
}
]
}
I am trying to create a SAM template (serverless.template) in visual studio to publish my API Gateway. I have a couple of errors being produced within the template validation (in Visual Studio) that I'm unable to resolve. When published, the stack deploys, but there is no usage plan(s) or api key(s) created (or rather, they are created but not viewable in the console, they come up as 'invalid reference' if you try to view them via Cloudformation > Resources, and they don't show up at all in the API Gateway console).
The errors are:
ServerlessRestApiDeployment26aad1646f is an unknown reference
"ServerlessRestApiProdStage": {
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "ServerlessRestApiDeployment26aad1646f"
},
"RestApiId": {
"Ref": "ServerlessRestApi"
},
"StageName": "Prod"
}
},
And
ServerlessRestApiProdStage is an invalid type for this reference
"APIGatewayHeartInHandKey": {
"Type": "AWS::ApiGateway::ApiKey",
"DependsOn": [
"ServerlessRestApi",
"ServerlessRestApiProdStage"
],
"Properties": {
"Name": "HeartInHandApiKey",
"Description": "Api Key for Heart In Hand",
"Enabled": true,
"GenerateDistinctId": true,
"StageKeys": [
{
"RestApiId": {
"Ref": "ServerlessRestApi"
},
"StageName": {
"Ref": "ServerlessRestApiProdStage"
}
}
]
}
},
The full SAM template shown below.
{
"AWSTemplateFormatVersion": "2010-09-09",
"Transform": "AWS::Serverless-2016-10-31",
"Description": "API Gateway to access InSite data-store",
"Resources": {
"Get": {
"Type": "AWS::Serverless::Function",
"Properties": {
"VpcConfig": {
"SecurityGroupIds": [
"sg-111a1476"
],
"SubnetIds": [
"subnet-3029a769",
"subnet-5ec0b928"
]
},
"Handler": "AWSServerlessInSiteDataGw::AWSServerlessInSiteDataGw.Functions::Get",
"Runtime": "dotnetcore2.0",
"CodeUri": "",
"MemorySize": 256,
"Timeout": 30,
"Role": null,
"Policies": [
"AWSLambdaBasicExecutionRole",
"AWSLambdaVPCAccessExecutionRole",
"AmazonSSMFullAccess"
],
"Events": {
"PutResource": {
"Type": "Api",
"Properties": {
"Path": "/",
"Method": "GET"
}
}
}
}
},
"GetTableBasic": {
"Type": "AWS::Serverless::Function",
"Properties": {
"VpcConfig": {
"SecurityGroupIds": [
"sg-111a1476"
],
"SubnetIds": [
"subnet-3029a769",
"subnet-5ec0b928"
]
},
"Handler": "AWSServerlessInSiteDataGw::AWSServerlessInSiteDataGw.Functions::GetTableBasic",
"Runtime": "dotnetcore2.0",
"CodeUri": "",
"MemorySize": 256,
"Timeout": 30,
"Role": null,
"Policies": [
"AWSLambdaBasicExecutionRole",
"AWSLambdaVPCAccessExecutionRole",
"AmazonSSMFullAccess"
],
"Events": {
"PutResource": {
"Type": "Api",
"Properties": {
"Path": "/tables/{tableid}/{columnid}",
"Method": "GET"
}
}
}
}
},
"GetColumnList": {
"Type": "AWS::Serverless::Function",
"Properties": {
"VpcConfig": {
"SecurityGroupIds": [
"sg-111a1476"
],
"SubnetIds": [
"subnet-3029a769",
"subnet-5ec0b928"
]
},
"Handler": "AWSServerlessInSiteDataGw::AWSServerlessInSiteDataGw.Functions::GetColumnList",
"Runtime": "dotnetcore2.0",
"CodeUri": "",
"MemorySize": 256,
"Timeout": 30,
"Role": null,
"Policies": [
"AWSLambdaBasicExecutionRole",
"AWSLambdaVPCAccessExecutionRole",
"AmazonSSMFullAccess"
],
"Events": {
"PutResource": {
"Type": "Api",
"Properties": {
"Path": "/list/columns/{tableid}",
"Method": "GET"
}
}
}
}
},
"GetTableList": {
"Type": "AWS::Serverless::Function",
"Properties": {
"VpcConfig": {
"SecurityGroupIds": [
"sg-111a1476"
],
"SubnetIds": [
"subnet-3029a769",
"subnet-5ec0b928"
]
},
"Handler": "AWSServerlessInSiteDataGw::AWSServerlessInSiteDataGw.Functions::GetTableList",
"Runtime": "dotnetcore2.0",
"CodeUri": "",
"MemorySize": 256,
"Timeout": 30,
"Role": null,
"Policies": [
"AWSLambdaBasicExecutionRole",
"AWSLambdaVPCAccessExecutionRole",
"AmazonSSMFullAccess"
],
"Events": {
"PutResource": {
"Type": "Api",
"Properties": {
"Path": "/list/tables",
"Method": "GET"
}
}
}
}
},
"PostClickCollectNotification": {
"Type": "AWS::Serverless::Function",
"Properties": {
"VpcConfig": {
"SecurityGroupIds": [
"sg-111a1476"
],
"SubnetIds": [
"subnet-3029a769",
"subnet-5ec0b928"
]
},
"Handler": "AWSServerlessInSiteDataGw::AWSServerlessInSiteDataGw.Functions::PostClickCollectNotification",
"Runtime": "dotnetcore2.0",
"CodeUri": "",
"MemorySize": 256,
"Timeout": 30,
"Role": null,
"Policies": [
"AWSLambdaBasicExecutionRole",
"AWSLambdaVPCAccessExecutionRole",
"AmazonSSMFullAccess"
],
"Events": {
"PutResource": {
"Type": "Api",
"Properties": {
"Path": "/datagw/general/webhook/ccnotify",
"Method": "POST"
}
}
}
}
},
"PostClickCollectStockUpdate": {
"Type": "AWS::Serverless::Function",
"Properties": {
"VpcConfig": {
"SecurityGroupIds": [
"sg-111a1476"
],
"SubnetIds": [
"subnet-3029a769",
"subnet-5ec0b928"
]
},
"Handler": "AWSServerlessInSiteDataGw::AWSServerlessInSiteDataGw.Functions::PostClickCollectStockUpdate",
"Runtime": "dotnetcore2.0",
"CodeUri": "",
"MemorySize": 256,
"Timeout": 30,
"Role": null,
"Policies": [
"AWSLambdaBasicExecutionRole",
"AWSLambdaVPCAccessExecutionRole",
"AmazonSSMFullAccess"
],
"Events": {
"PutResource": {
"Type": "Api",
"Properties": {
"Path": "/datagw/general/post/sohupdate",
"Method": "POST"
}
}
}
}
},
"GetTableResponse": {
"Type": "AWS::Serverless::Function",
"Properties": {
"VpcConfig": {
"SecurityGroupIds": [
"sg-111a1476"
],
"SubnetIds": [
"subnet-3029a769",
"subnet-5ec0b928"
]
},
"Handler": "AWSServerlessInSiteDataGw::AWSServerlessInSiteDataGw.Functions::GetTableResponse",
"Runtime": "dotnetcore2.0",
"CodeUri": "",
"MemorySize": 256,
"Timeout": 30,
"Role": null,
"Policies": [
"AWSLambdaBasicExecutionRole",
"AWSLambdaVPCAccessExecutionRole",
"AmazonSSMFullAccess"
],
"Events": {
"PutResource": {
"Type": "Api",
"Properties": {
"Path": "datagw/general/table/get/{tableid}",
"Method": "GET"
}
}
}
}
},
"ServerlessRestApi": {
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
"Description":"This is a placeholder for the description of this web api",
"ApiKeySourceType":"HEADER",
"Body": {
"info": {
"version": "1.0",
"title": {
"Ref": "AWS::StackName"
}
},
"paths": {
"/list/tables": {
"get": {
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"type": "aws_proxy",
"uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetTableList.Arn}/invocations"
}
},
"responses": {}
}
},
"/list/columns/{tableid}": {
"get": {
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"type": "aws_proxy",
"uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetColumnList.Arn}/invocations"
}
},
"responses": {}
}
},
"datagw/general/table/get/{tableid}": {
"get": {
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"type": "aws_proxy",
"uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetTableResponse.Arn}/invocations"
}
},
"responses": {}
}
},
"/": {
"get": {
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"type": "aws_proxy",
"uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Get.Arn}/invocations"
}
},
"responses": {}
}
},
"/tables/{tableid}/{columnid}": {
"get": {
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"type": "aws_proxy",
"uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetTableBasic.Arn}/invocations"
}
},
"responses": {}
}
}
},
"swagger": "2.0"
}
}
},
"ServerlessRestApiProdStage": {
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"DeploymentId": {
"Ref": "ServerlessRestApiDeployment26aad1646f"
},
"RestApiId": {
"Ref": "ServerlessRestApi"
},
"StageName": "Prod"
}
},
"CustomLambdaExecutionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
},
"Action": [
"sts:AssumeRole"
]
}
]
},
"Policies": [
{
"PolicyName": "lambdaAccessApiKeys",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"apigateway:GET"
],
"Resource": {
"Fn::Sub": [
"arn:aws:apigateway:ap-southeast-2::/apikeys/${__keyId__}",
{
"__keyId__": {
"Ref": "APIGatewayHeartInHandKey"
}
}
]
}
}
]
}
}
]
}
},
"GetApiKeyValueLambdaFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"ZipFile": {
"Fn::Join": [
"\n",
[
"import json",
"import boto3",
"client = boto3.client('apigateway')",
"def lambda_handler(event, context):",
" response = client.get_api_key(",
" apiKey= event['apiKeyId'],",
" includeValue = True",
")",
" return {",
" 'statusCode': 200,",
" 'body': response['value']}"
]
]
}
},
"Handler": "index.lambda_handler",
"Runtime": "python3.6",
"Timeout": 30,
"Role": {
"Fn::GetAtt": [
"CustomLambdaExecutionRole",
"Arn"
]
}
}
},
"APIGatewayUsagePlanInternal": {
"Type": "AWS::ApiGateway::UsagePlan",
"Properties": {
"ApiStages": [
{
"ApiId": {
"Ref": "ServerlessRestApi"
},
"Stage": {
"Ref": "ServerlessRestApiProdStage"
}
}
],
"Description": "Internal Apps Usage Plan",
"UsagePlanName": "Insite-datagw-InternalAppPlan"
}
},
"APIGatewayUsagePlanExternal": {
"Type": "AWS::ApiGateway::UsagePlan",
"Properties": {
"ApiStages": [
{
"ApiId": {
"Ref": "ServerlessRestApi"
},
"Stage": {
"Ref": "ServerlessRestApiProdStage"
}
}
],
"Description": "External Apps Usage Plan",
"UsagePlanName": "InSite-datagw-ExternalAppPlan"
}
},
"APIGatewayHeartInHandKey": {
"Type": "AWS::ApiGateway::ApiKey",
"DependsOn": [
"ServerlessRestApi",
"ServerlessRestApiProdStage"
],
"Properties": {
"Name": "HeartInHandApiKey",
"Description": "Api Key for Heart In Hand",
"Enabled": true,
"GenerateDistinctId": true,
"StageKeys": [
{
"RestApiId": {
"Ref": "ServerlessRestApi"
},
"StageName": {
"Ref": "ServerlessRestApiProdStage"
}
}
]
}
},
"LinkHeartInHandKey": {
"Type": "AWS::ApiGateway::UsagePlanKey",
"Properties": {
"KeyId": {
"Ref": "APIGatewayHeartInHandKey"
},
"KeyType": "API_KEY",
"UsagePlanId": {
"Ref": "APIGatewayUsagePlanInternal"
}
}
},
"APIGatewayPricelineSiteKey": {
"Type": "AWS::ApiGateway::ApiKey",
"DependsOn": [
"ServerlessRestApi",
"ServerlessRestApiProdStage"
],
"Properties": {
"Name": "PricelineSiteApiKey",
"Description": "Api Key for Priceline Website",
"Enabled": true,
"GenerateDistinctId": true,
"StageKeys": [
{
"RestApiId": {
"Ref": "ServerlessRestApi"
},
"StageName": {
"Ref": "ServerlessRestApiProdStage"
}
}
]
}
},
"LinkPricelineSiteKey": {
"Type": "AWS::ApiGateway::UsagePlanKey",
"Properties": {
"KeyId": {
"Ref": "APIGatewayPricelineSiteKey"
},
"KeyType": "API_KEY",
"UsagePlanId": {
"Ref": "APIGatewayUsagePlanInternal"
}
}
}
},
"Outputs": {
"ApiURL": {
"Description": "API endpoint URL for Prod environment",
"Value": {
"Fn::Sub": "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/"
}
}
}
}
it looks like you're trying to use features of the AWS::Serverless::Api resource from SAM without defining an AWS::Serverless::Api in your template.
In order to fix the issues you've brought up, it looks like you need to:
Remove the ServerlessRestApiProdStage resource
Sam will generate this resource (and the deployment resource) for you if you use an AWS::Serverless::Api resource.
Convert your AWS::ApiGateway::RestApi resource into an AWS::Serverless::Api resource:
Remove ApiKeySourceType property and add "x-amazon-apigateway-api-key-source" : "HEADER", to the swagger,
Change the Type from AWS::ApiGateway::RestApi to AWS::Serverless::Api
"ServerlessRestApi": {
"Type": "AWS::Serverless::RestApi",
"Properties": {
"Description":"This is a placeholder for the description of this web api",
"Body": {
"info": {
"version": "1.0",
"title": {
"Ref": "AWS::StackName"
}
},
"x-amazon-apigateway-api-key-source" : "HEADER",
"paths": {
...
I'm new to JSONata and so still getting my head around it. I need to pull data out of a nested object, for example from :
{
"transaction": {
"id": "de112b4b-82e2-4172-a89f-68724c90b692"
},
"domain": {
"id": "realworld"
},
"listing": {
"spanner": {
"information": {
"type": {
"VENDOR": "Charlie"
},
"variables": {
},
"uid": "08_spanner",
"mode": {
"store": "bob"
},
"version": "1",
"name": "Harrold"
}
},
"hammer": {
"information": {
"type": {
"VENDOR": "Cliff"
},
"variables": {
},
"uid": "08_hammer",
"mode": {
"store": "steve"
},
"version": "1",
"name": "Mike"
}
},
"wrench": {
"information": {
"type": {
"VENDOR": "Dave"
},
"variables": {
},
"uid": "08_wrench",
"mode": {
"store": "bob"
},
"version": "1",
"name": "Kent"
}
}
}
}
... I need to pull out the listing data with it's "information", but without the information key. So the result would look like:
{
"spanner": {
"type": {
"VENDOR": "Charlie"
},
"variables": {
},
"uid": "08_spanner",
"mode": {
"store": "bob"
},
"version": "1",
"name": "Harrold"
},
"hammer": {
"type": {
"VENDOR": "Cliff"
},
"variables": {
},
"uid": "08_hammer",
"mode": {
"store": "steve"
},
"version": "1",
"name": "Mike"
},
"wrench": {
"type": {
"VENDOR": "Dave"
},
"variables": {
},
"uid": "08_wrench",
"mode": {
"store": "bob"
},
"version": "1",
"name": "Kent"
}
}
I have been messing around on http://try.jsonata.org/ and can see how powerful the library is but so far no success at achieving this goal. Any and all help is appreciated :).
The following expression will do this:
listing.$each(function($value, $key) {
{ $key: $value.information }
}) ~> $merge()
See http://try.jsonata.org/S17Erm85z
I have an issue regarding ElasticSearch and More like this query.
Having mapping:
{
"directory.v1": {
"mappings": {
"profile.event": {
"properties": {
"event": {
"properties": {
"naics": {
"type": "nested",
"properties": {
"type": {
"type": "keyword"
},
"value": {
"type": "keyword"
}
}
}
}
},
"user_id": {
"type": "long"
}
}
}
}
}
}
and document (A) as a source and document (B) to be found with more like this query (for A)
Profile A (used as source):
{
"_index": "directory.v1",
"_type": "profile.event",
"_id": "83731111.559",
"_score": 1,
"_source": {
"user_id": 8373,
"event": {
"naics": [
{
"value": 331,
"type": "naics"
},
{
"value": 74,
"type": "naics"
},
{
"value": 938,
"type": "naics"
},
{
"value": 2048,
"type": "naics"
},
{
"value": 939,
"type": "naics"
},
{
"value": 2049,
"type": "naics"
},
{
"value": 940,
"type": "naics"
},
{
"value": 2050,
"type": "naics"
},
{
"value": 941,
"type": "naics"
},
{
"value": 2051,
"type": "naics"
},
{
"value": 942,
"type": "naics"
},
{
"value": 2052,
"type": "naics"
},
{
"value": 943,
"type": "naics"
},
{
"value": 2053,
"type": "naics"
},
{
"value": 944,
"type": "naics"
},
{
"value": 2054,
"type": "naics"
},
{
"value": 945,
"type": "naics"
},
{
"value": 2055,
"type": "naics"
},
{
"value": 473,
"type": "naics"
},
{
"value": 128,
"type": "naics"
},
{
"value": 10,
"type": "naics"
},
{
"value": 1242,
"type": "naics"
},
{
"value": 472,
"type": "naics"
},
{
"value": 1241,
"type": "naics"
}
]
}
}
}
Profile B:
{
"_index": "directory.v1",
"_type": "profile.event",
"_id": "46124111.559",
"_score": 1,
"_source": {
"user_id": 46124,
"event": {
"naics": [
{
"value": 331,
"type": "naics"
},
{
"value": 74,
"type": "naics"
},
{
"value": 938,
"type": "naics"
},
{
"value": 2048,
"type": "naics"
},
{
"value": 939,
"type": "naics"
},
{
"value": 2049,
"type": "naics"
},
{
"value": 940,
"type": "naics"
},
{
"value": 2050,
"type": "naics"
},
{
"value": 941,
"type": "naics"
},
{
"value": 2051,
"type": "naics"
},
{
"value": 942,
"type": "naics"
},
{
"value": 2052,
"type": "naics"
},
{
"value": 943,
"type": "naics"
},
{
"value": 2053,
"type": "naics"
},
{
"value": 944,
"type": "naics"
},
{
"value": 2054,
"type": "naics"
},
{
"value": 945,
"type": "naics"
},
{
"value": 2055,
"type": "naics"
}
]
}
}
}
where B doc has all elements (naics) included in A document.
So that I really do not understand why for query:
{
"query": {
"nested": {
"path": "event.naics",
"query": {
"more_like_this": {
"like": [
{
"_id": "83731111.559",
"_type": "profile.event"
}
],
"fields": [
"event.naics.value"
],
"min_term_freq": 1,
"min_doc_freq": 1,
"minimum_should_match": "8%"
}
}
}
}
}
I have results!!
but when I increase min_should_match >= 9% it does not match at all and I get no results.
Also tried to do something like this which gets me some results up to 11%
{
"query": {
"nested": {
"path": "event.naics",
"query": {
"more_like_this": {
"like": [
{
"_id": "83731111.559",
"_type": "profile.event"
}
],
"fields": [
"event.naics.*"
],
"min_term_freq": 1,
"min_doc_freq": 1,
"minimum_should_match": "11%"
}
}
}
}
}
And termvecor for source document is:
{
"_index": "directory.v1",
"_type": "profile.event",
"_id": "83731111.559",
"_version": 5,
"found": true,
"took": 0,
"term_vectors": {}
}
If you get the term vector for document "A" for field event.naics.value you will see you have 24 terms in total each with term frequency 1.
So when you do 8% match that will be rounded down to 1 clause of the 24 generated should clauses, so you get a match. But 9% of 24 will round to 2 clauses should match which is no bueno as each of your nested document has only one value.
For calculation details you can see the bottom of this page
https://github.com/elastic/elasticsearch/blob/99f88f15c5febbca2d13b5b5fda27b844153bf1a/server/src/main/java/org/elasticsearch/common/lucene/search/Queries.java
And morelikethis source is here
https://github.com/elastic/elasticsearch/blob/46a79127edfb0cc93b7580624010ff81ca0cb2f4/server/src/main/java/org/elasticsearch/common/lucene/search/MoreLikeThisQuery.java
Term vector
POST /directory.v1/profile.event/83731111.559/_termvectors
{
"fields":["event.naics.value"],
"offsets" : false,
"payloads" : false,
"positions" : false,
"term_statistics" : true,
"field_statistics" : true
}