Azure maps autocomplete - country and city only - azure-maps

I am writing an autocomplete service and want to get only country and city calling a Microsoft Azure service - with no addresses and POI or such.
I currently found Address Search where I would need to call https://atlas.microsoft.com/search/address, but it returns addresses, not cities and countries - which leads to many duplicates.
Plus, If I need to have a fixed number of auto complete options - say, 15 - it is going to require multiple calls to the service until I have all 15. On top of that, I will never know if there are more results for a typed partial country/city combination or not.
I don't want to use a fixed list as it needs maintenance.
I would not want to use another data provider for now, if it is possible to achieve with Azure.

This isn't supported yet, but is planned for the future. The closest that could be done now would be to use the https://learn.microsoft.com/en-us/rest/api/maps/search/getsearchaddressstructured service but it requires a country code to be specified, so you would only get cities for the specified country. For example, passing in new as the municipality as done in the following query:
https://atlas.microsoft.com/search/address/structured/json?api-version=1&municipality=new&countryCode=US&subscription-key=<Your_Key>
will return the following city results:
New York
New Orleans
New Braunfels
New Port Richey
New Bern
New Haven
New Iberia
New Castle
New Bedford
New Albany
Here is the raw response
{
"summary": {
"query": "new",
"queryType": "NON_NEAR",
"queryTime": 23,
"numResults": 10,
"offset": 0,
"totalResults": 998,
"fuzzyLevel": 1
},
"results": [
{
"type": "Geography",
"id": "US/GEO/p0/1167",
"score": 2.6649377346,
"entityType": "Municipality",
"address": {
"municipality": "New York",
"countrySubdivision": "NY",
"countrySubdivisionName": "New York",
"countryCode": "US",
"country": "United States",
"countryCodeISO3": "USA",
"freeformAddress": "New York, NY"
},
"position": {
"lat": 40.71305,
"lon": -74.00723
},
"viewport": {
"topLeftPoint": {
"lat": 40.9175,
"lon": -74.25564
},
"btmRightPoint": {
"lat": 40.49587,
"lon": -73.70027
}
},
"boundingBox": {
"topLeftPoint": {
"lat": 40.9175,
"lon": -74.25564
},
"btmRightPoint": {
"lat": 40.49587,
"lon": -73.70027
}
},
"dataSources": {
"geometry": {
"id": "d49d86a4-0f4b-45f2-b607-31a84d02af00"
}
}
},
{
"type": "Geography",
"id": "US/GEO/p0/90711",
"score": 2.5113995075,
"entityType": "Municipality",
"address": {
"municipality": "New Orleans",
"countrySecondarySubdivision": "Orleans",
"countrySubdivision": "LA",
"countrySubdivisionName": "Louisiana",
"countryCode": "US",
"country": "United States",
"countryCodeISO3": "USA",
"freeformAddress": "New Orleans, LA"
},
"position": {
"lat": 29.95176,
"lon": -90.07462
},
"viewport": {
"topLeftPoint": {
"lat": 30.21747,
"lon": -90.24051
},
"btmRightPoint": {
"lat": 29.86582,
"lon": -89.62506
}
},
"boundingBox": {
"topLeftPoint": {
"lat": 30.21747,
"lon": -90.24051
},
"btmRightPoint": {
"lat": 29.86582,
"lon": -89.62506
}
},
"dataSources": {
"geometry": {
"id": "0000554c-4100-3c00-0000-0000596a7628"
}
}
},
{
"type": "Geography",
"id": "US/GEO/p0/103135",
"score": 2.4384012222,
"entityType": "Municipality",
"address": {
"municipality": "New Braunfels",
"countrySubdivision": "TX",
"countrySubdivisionName": "Texas",
"countryCode": "US",
"country": "United States",
"countryCodeISO3": "USA",
"freeformAddress": "New Braunfels, TX"
},
"position": {
"lat": 29.70988,
"lon": -98.11973
},
"viewport": {
"topLeftPoint": {
"lat": 29.91293,
"lon": -98.34627
},
"btmRightPoint": {
"lat": 29.59298,
"lon": -97.9908
}
},
"boundingBox": {
"topLeftPoint": {
"lat": 29.91293,
"lon": -98.34627
},
"btmRightPoint": {
"lat": 29.59298,
"lon": -97.9908
}
},
"dataSources": {
"geometry": {
"id": "9d7bf985-115b-423a-979a-97cc093c3166"
}
}
},
{
"type": "Geography",
"id": "US/GEO/p0/23041",
"score": 2.4345231056,
"entityType": "Municipality",
"address": {
"municipality": "New Port Richey",
"countrySecondarySubdivision": "Pasco",
"countrySubdivision": "FL",
"countrySubdivisionName": "Florida",
"countryCode": "US",
"country": "United States",
"countryCodeISO3": "USA",
"freeformAddress": "New Port Richey, FL"
},
"position": {
"lat": 28.2502,
"lon": -82.71408
},
"viewport": {
"topLeftPoint": {
"lat": 28.33939,
"lon": -82.76461
},
"btmRightPoint": {
"lat": 28.17319,
"lon": -82.57478
}
},
"boundingBox": {
"topLeftPoint": {
"lat": 28.33939,
"lon": -82.76461
},
"btmRightPoint": {
"lat": 28.17319,
"lon": -82.57478
}
},
"dataSources": {
"geometry": {
"id": "00005546-3300-3c00-0000-000059a7e5e6"
}
}
},
{
"type": "Geography",
"id": "US/GEO/p0/27115",
"score": 2.414732933,
"entityType": "Municipality",
"address": {
"municipality": "New Bern",
"countrySecondarySubdivision": "Craven",
"countrySubdivision": "NC",
"countrySubdivisionName": "North Carolina",
"countryCode": "US",
"country": "United States",
"countryCodeISO3": "USA",
"freeformAddress": "New Bern, NC"
},
"position": {
"lat": 35.10832,
"lon": -77.04612
},
"viewport": {
"topLeftPoint": {
"lat": 35.28085,
"lon": -77.26051
},
"btmRightPoint": {
"lat": 34.90304,
"lon": -76.83165
}
},
"boundingBox": {
"topLeftPoint": {
"lat": 35.28085,
"lon": -77.26051
},
"btmRightPoint": {
"lat": 34.90304,
"lon": -76.83165
}
},
"dataSources": {
"geometry": {
"id": "00004e43-3300-3c00-0000-0000596be1d9"
}
}
},
{
"type": "Geography",
"id": "US/GEO/p0/60622",
"score": 2.4027762413,
"entityType": "Municipality",
"address": {
"municipality": "New Haven",
"countrySecondarySubdivision": "New Haven",
"countrySubdivision": "CT",
"countrySubdivisionName": "Connecticut",
"countryCode": "US",
"country": "United States",
"countryCodeISO3": "USA",
"freeformAddress": "New Haven, CT"
},
"position": {
"lat": 41.30825,
"lon": -72.92416
},
"viewport": {
"topLeftPoint": {
"lat": 41.35038,
"lon": -72.99807
},
"btmRightPoint": {
"lat": 41.2464,
"lon": -72.81773
}
},
"boundingBox": {
"topLeftPoint": {
"lat": 41.35038,
"lon": -72.99807
},
"btmRightPoint": {
"lat": 41.2464,
"lon": -72.81773
}
},
"dataSources": {
"geometry": {
"id": "00005543-5400-3c00-0000-0000596911a2"
}
}
},
{
"type": "Geography",
"id": "US/GEO/p0/90802",
"score": 2.4020097256,
"entityType": "Municipality",
"address": {
"municipality": "New Iberia",
"countrySecondarySubdivision": "Iberia",
"countrySubdivision": "LA",
"countrySubdivisionName": "Louisiana",
"countryCode": "US",
"country": "United States",
"countryCodeISO3": "USA",
"freeformAddress": "New Iberia, LA"
},
"position": {
"lat": 30.00256,
"lon": -91.81698
},
"viewport": {
"topLeftPoint": {
"lat": 30.12129,
"lon": -91.9944
},
"btmRightPoint": {
"lat": 29.73782,
"lon": -91.65921
}
},
"boundingBox": {
"topLeftPoint": {
"lat": 30.12129,
"lon": -91.9944
},
"btmRightPoint": {
"lat": 29.73782,
"lon": -91.65921
}
},
"dataSources": {
"geometry": {
"id": "0000554c-4100-3c00-0000-00005968eae5"
}
}
},
{
"type": "Geography",
"id": "US/GEO/p0/61589",
"score": 2.3937933445,
"entityType": "Municipality",
"address": {
"municipality": "New Castle",
"countrySecondarySubdivision": "New Castle",
"countrySubdivision": "DE",
"countrySubdivisionName": "Delaware",
"countryCode": "US",
"country": "United States",
"countryCodeISO3": "USA",
"freeformAddress": "New Castle, DE"
},
"position": {
"lat": 39.66066,
"lon": -75.56184
},
"viewport": {
"topLeftPoint": {
"lat": 39.7245,
"lon": -75.66496
},
"btmRightPoint": {
"lat": 39.55219,
"lon": -75.50945
}
},
"boundingBox": {
"topLeftPoint": {
"lat": 39.7245,
"lon": -75.66496
},
"btmRightPoint": {
"lat": 39.55219,
"lon": -75.50945
}
},
"dataSources": {
"geometry": {
"id": "00005544-4500-3c00-0000-000059685073"
}
}
},
{
"type": "Geography",
"id": "US/GEO/p0/36482",
"score": 2.3928732872,
"entityType": "Municipality",
"address": {
"municipality": "New Bedford",
"countrySecondarySubdivision": "Bristol",
"countrySubdivision": "MA",
"countrySubdivisionName": "Massachusetts",
"countryCode": "US",
"country": "United States",
"countryCodeISO3": "USA",
"freeformAddress": "New Bedford, MA"
},
"position": {
"lat": 41.63405,
"lon": -70.92766
},
"viewport": {
"topLeftPoint": {
"lat": 41.74525,
"lon": -70.97843
},
"btmRightPoint": {
"lat": 41.58185,
"lon": -70.87872
}
},
"boundingBox": {
"topLeftPoint": {
"lat": 41.74525,
"lon": -70.97843
},
"btmRightPoint": {
"lat": 41.58185,
"lon": -70.87872
}
},
"dataSources": {
"geometry": {
"id": "0000554d-4100-3c00-0000-00005969fc6d"
}
}
},
{
"type": "Geography",
"id": "US/GEO/p0/12185",
"score": 2.3897461891,
"entityType": "Municipality",
"address": {
"municipality": "New Albany",
"countrySecondarySubdivision": "Floyd",
"countrySubdivision": "IN",
"countrySubdivisionName": "Indiana",
"countryCode": "US",
"country": "United States",
"countryCodeISO3": "USA",
"freeformAddress": "New Albany, IN"
},
"position": {
"lat": 38.28351,
"lon": -85.823
},
"viewport": {
"topLeftPoint": {
"lat": 38.40435,
"lon": -85.8853
},
"btmRightPoint": {
"lat": 38.22944,
"lon": -85.76089
}
},
"boundingBox": {
"topLeftPoint": {
"lat": 38.40435,
"lon": -85.8853
},
"btmRightPoint": {
"lat": 38.22944,
"lon": -85.76089
}
},
"dataSources": {
"geometry": {
"id": "00005549-4e00-3c00-0000-0000596b63cf"
}
}
}
]
}

There is an end point in the Atlas API which might be closer to what we need - Fuzzy search.
It allows to set a typeahead flag and you can filter on entity type, so, for a GET reauest https://atlas.microsoft.com/search/fuzzy/json?api-version=1.0&query=Paris&typeahead=true&limit=3&entityType=Municipality,MunicipalitySubdivision,CountryTertiarySubdivision,CountrySubdivision
with your subscription key in the header
and an example return would be
"summary": {
"query": "paris",
"queryType": "NON_NEAR",
"queryTime": 26,
"numResults": 3,
"offset": 0,
"totalResults": 141,
"fuzzyLevel": 1,
"queryIntent": []
},
"results": [
{
"type": "Geography",
"id": "FR/GEO/p0/13312",
"score": 2.5989630222,
"entityType": "Municipality",
"address": {
"municipality": "Paris",
"countrySecondarySubdivision": "Paris",
"countrySubdivision": "Île-de-France",
"countryCode": "FR",
"country": "France",
"countryCodeISO3": "FRA",
"freeformAddress": "Paris"
},
"position": {
"lat": 48.85689,
"lon": 2.35085
},
"viewport": {
"topLeftPoint": {
"lat": 48.90216,
"lon": 2.2241
},
"btmRightPoint": {
"lat": 48.81552,
"lon": 2.46991
}
},
"boundingBox": {
"topLeftPoint": {
"lat": 48.90216,
"lon": 2.2241
},
"btmRightPoint": {
"lat": 48.81552,
"lon": 2.46991
}
},
"dataSources": {
"geometry": {
"id": "00005858-5800-1200-0000-000077369045"
}
}
},
{
"type": "Geography",
"id": "US/GEO/p0/119280",
"score": 2.4116733074,
"entityType": "Municipality",
"address": {
"municipality": "Paris",
"countrySecondarySubdivision": "Lamar",
"countrySubdivision": "TX",
"countrySubdivisionName": "Texas",
"countryCode": "US",
"country": "United States",
"countryCodeISO3": "USA",
"freeformAddress": "Paris, TX"
},
"position": {
"lat": 33.66143,
"lon": -95.55632
},
"viewport": {
"topLeftPoint": {
"lat": 33.86768,
"lon": -95.66163
},
"btmRightPoint": {
"lat": 33.38955,
"lon": -95.31052
}
},
"boundingBox": {
"topLeftPoint": {
"lat": 33.86768,
"lon": -95.66163
},
"btmRightPoint": {
"lat": 33.38955,
"lon": -95.31052
}
},
"dataSources": {
"geometry": {
"id": "00005554-3100-3c00-0000-0000596a4495"
}
}
},
{
"type": "Geography",
"id": "US/GEO/p0/106765",
"score": 2.4046759605,
"entityType": "Municipality",
"address": {
"municipality": "Paris",
"countrySecondarySubdivision": "Henry",
"countrySubdivision": "TN",
"countrySubdivisionName": "Tennessee",
"countryCode": "US",
"country": "United States",
"countryCodeISO3": "USA",
"freeformAddress": "Paris, TN"
},
"position": {
"lat": 36.30275,
"lon": -88.32636
},
"viewport": {
"topLeftPoint": {
"lat": 36.42548,
"lon": -88.59662
},
"btmRightPoint": {
"lat": 36.18254,
"lon": -88.15962
}
},
"boundingBox": {
"topLeftPoint": {
"lat": 36.42548,
"lon": -88.59662
},
"btmRightPoint": {
"lat": 36.18254,
"lon": -88.15962
}
},
"dataSources": {
"geometry": {
"id": "0000544e-3100-3c00-0000-00005969642b"
}
}
}
]
}

Related

How to create a JSON structure in ReactJS

I have a use-case to create a JSON structure in React in order to POST an API request. The JSON structure body contains objects and arrays.
Please let me know how to create it in ReactJS.
Below is the sample JSON structure that needs to be created using ReactJS:-
{
"transactionAmount": {
"currency": "INR",
"value": 1220.38
},
"transactionDate": "2020-05-18T00:00:00Z",
"tripData": {
"agencyBooked": false,
"legs": [
{
"endLocation": {
"countryCode": "IN",
"city": "Delhi",
"name": "Indira Gandhi International"
},
"startDate": "2020-05-22",
"startTime": "08:00",
"returnLeg": false,
"startLocation": {
"countryCode": "US",
"city": "San Francisco",
"name": "San Francisco International"
},
"endTime": "21:00",
"endDate": "2020-05-22",
"startLocationDetail": "none"
},
{
"endLocation": {
"countryCode": "US",
"city": "San Francisco",
"name": "San Francisco International"
},
"returnLeg": true,
"startDate": "2020-05-24",
"startLocation": {
"countryCode": "IN",
"city": "Delhi",
"name": "Indira Gandhi International"
},
"startTime": "17:00"
}
],
"segmentType": {
"category": "REQ_SEG_AIRFR",
"code": "AIRFR"
},
"selfBooked": false,
"tripType": "ROUND_TRIP"
}
}
You can simply make a JSON format like this.
const dummyObject = {
name: 'Dummy',
age: 22,
about: {
hobbies: ['soccer']
},
works: true
}

retrieving array from json as a table in Kusto

I am trying to retrieve all the rows from a Json array. The json is similar to the one shown below.
{
"messageId": "123",
"fileName": "abc.json",
"payload": {
"routeStatus": "FINAL",
"activities": [
{
"durationSeconds": 1800,
"location": {
"longitude": 151.2603,
"latitude": -33.7644
},
"type": "DEPART",
"slot": {
"start": "2020-04-14T19:05:00.0000000Z",
"cost": null,
"end": "2020-04-15T03:30:00.0000000Z"
}
},
{
"durationSeconds": 1100,
"type": "DRIVE"
},
{
"durationSeconds": 360,
"location": {
"longitude": 151.21814,
"latitude": -33.756319
},
"type": "SERVICE",
"slot": {
"start": "2020-04-14T20:00:00.0000000Z",
"cost": null,
"end": "2020-04-15T00:45:00.0000000Z"
}
},
{
"durationSeconds": 164,
"type": "DRIVE"
}
],
"truck": "XYZ"
}
}
I would like to get all the attributes under the activities in a table as I would need to filter and join to other tables. I am only able to retrieve one row from the array. Any pointers would be helpful.
you can use mv-expand or mv-apply.
for example:
print d = dynamic({
"messageId": "123",
"fileName": "abc.json",
"payload": {
"routeStatus": "FINAL",
"activities": [
{
"durationSeconds": 1800,
"location": {
"longitude": 151.2603,
"latitude": -33.7644
},
"type": "DEPART",
"slot": {
"start": "2020-04-14T19:05:00.0000000Z",
"cost": null,
"end": "2020-04-15T03:30:00.0000000Z"
}
},
{
"durationSeconds": 1100,
"type": "DRIVE"
},
{
"durationSeconds": 360,
"location": {
"longitude": 151.21814,
"latitude": -33.756319
},
"type": "SERVICE",
"slot": {
"start": "2020-04-14T20:00:00.0000000Z",
"cost": null,
"end": "2020-04-15T00:45:00.0000000Z"
}
},
{
"durationSeconds": 164,
"type": "DRIVE"
}
],
"truck": "XYZ"
}
})
| mv-expand d.payload.activities
| project durationSeconds = tolong(d_payload_activities.durationSeconds), type = tostring(d_payload_activities.type)

Http call output json to SQL record using Logic App

I am using Logic App and task is to make an HTTP call, get JSON , read 1 record of json at a time , insert into DB and repeat.
Output of this HTTP call is a json array:
[
{
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "Sincere#april.biz",
"address": {
"street": "Kulas Light",
"suite": "Apt. 556",
"city": "Gwenborough",
"zipcode": "92998-3874",
"geo": {
"lat": "-37.3159",
"lng": "81.1496"
}
},
"phone": "1-770-736-8031 x56442",
"website": "hildegard.org",
"company": {
"name": "Romaguera-Crona",
"catchPhrase": "Multi-layered client-server neural-net",
"bs": "harness real-time e-markets"
}
},
{
"id": 2,
"name": "Ervin Howell",
"username": "Antonette",
"email": "Shanna#melissa.tv",
"address": {
"street": "Victor Plains",
"suite": "Suite 879",
"city": "Wisokyburgh",
"zipcode": "90566-7771",
"geo": {
"lat": "-43.9509",
"lng": "-34.4618"
}
},
"phone": "010-692-6593 x09125",
"website": "anastasia.net",
"company": {
"name": "Deckow-Crist",
"catchPhrase": "Proactive didactic contingency",
"bs": "synergize scalable supply-chains"
}
},
{
"id": 3,
"name": "Clementine Bauch",
"username": "Samantha",
"email": "Nathan#yesenia.net",
"address": {
"street": "Douglas Extension",
"suite": "Suite 847",
"city": "McKenziehaven",
"zipcode": "59590-4157",
"geo": {
"lat": "-68.6102",
"lng": "-47.0653"
}
},
"phone": "1-463-123-4447",
"website": "ramiro.info",
"company": {
"name": "Romaguera-Jacobson",
"catchPhrase": "Face to face bifurcated interface",
"bs": "e-enable strategic applications"
}
},
{
"id": 4,
"name": "Patricia Lebsack",
"username": "Karianne",
"email": "Julianne.OConner#kory.org",
"address": {
"street": "Hoeger Mall",
"suite": "Apt. 692",
"city": "South Elvis",
"zipcode": "53919-4257",
"geo": {
"lat": "29.4572",
"lng": "-164.2990"
}
},
"phone": "493-170-9623 x156",
"website": "kale.biz",
"company": {
"name": "Robel-Corkery",
"catchPhrase": "Multi-tiered zero tolerance productivity",
"bs": "transition cutting-edge web services"
}
},
{
"id": 5,
"name": "Chelsey Dietrich",
"username": "Kamren",
"email": "Lucio_Hettinger#annie.ca",
"address": {
"street": "Skiles Walks",
"suite": "Suite 351",
"city": "Roscoeview",
"zipcode": "33263",
"geo": {
"lat": "-31.8129",
"lng": "62.5342"
}
},
"phone": "(254)954-1289",
"website": "demarco.info",
"company": {
"name": "Keebler LLC",
"catchPhrase": "User-centric fault-tolerant solution",
"bs": "revolutionize end-to-end systems"
}
},
{
"id": 6,
"name": "Mrs. Dennis Schulist",
"username": "Leopoldo_Corkery",
"email": "Karley_Dach#jasper.info",
"address": {
"street": "Norberto Crossing",
"suite": "Apt. 950",
"city": "South Christy",
"zipcode": "23505-1337",
"geo": {
"lat": "-71.4197",
"lng": "71.7478"
}
},
"phone": "1-477-935-8478 x6430",
"website": "ola.org",
"company": {
"name": "Considine-Lockman",
"catchPhrase": "Synchronised bottom-line interface",
"bs": "e-enable innovative applications"
}
},
{
"id": 7,
"name": "Kurtis Weissnat",
"username": "Elwyn.Skiles",
"email": "Telly.Hoeger#billy.biz",
"address": {
"street": "Rex Trail",
"suite": "Suite 280",
"city": "Howemouth",
"zipcode": "58804-1099",
"geo": {
"lat": "24.8918",
"lng": "21.8984"
}
},
"phone": "210.067.6132",
"website": "elvis.io",
"company": {
"name": "Johns Group",
"catchPhrase": "Configurable multimedia task-force",
"bs": "generate enterprise e-tailers"
}
},
{
"id": 8,
"name": "Nicholas Runolfsdottir V",
"username": "Maxime_Nienow",
"email": "Sherwood#rosamond.me",
"address": {
"street": "Ellsworth Summit",
"suite": "Suite 729",
"city": "Aliyaview",
"zipcode": "45169",
"geo": {
"lat": "-14.3990",
"lng": "-120.7677"
}
},
"phone": "586.493.6943 x140",
"website": "jacynthe.com",
"company": {
"name": "Abernathy Group",
"catchPhrase": "Implemented secondary concept",
"bs": "e-enable extensible e-tailers"
}
},
{
"id": 9,
"name": "Glenna Reichert",
"username": "Delphine",
"email": "Chaim_McDermott#dana.io",
"address": {
"street": "Dayna Park",
"suite": "Suite 449",
"city": "Bartholomebury",
"zipcode": "76495-3109",
"geo": {
"lat": "24.6463",
"lng": "-168.8889"
}
},
"phone": "(775)976-6794 x41206",
"website": "conrad.com",
"company": {
"name": "Yost and Sons",
"catchPhrase": "Switchable contextually-based project",
"bs": "aggregate real-time technologies"
}
},
{
"id": 10,
"name": "Clementina DuBuque",
"username": "Moriah.Stanton",
"email": "Rey.Padberg#karina.biz",
"address": {
"street": "Kattie Turnpike",
"suite": "Suite 198",
"city": "Lebsackbury",
"zipcode": "31428-2261",
"geo": {
"lat": "-38.2386",
"lng": "57.2232"
}
},
"phone": "024-648-3804",
"website": "ambrose.net",
"company": {
"name": "Hoeger LLC",
"catchPhrase": "Centralized empowering task-force",
"bs": "target end-to-end models"
}
}
]
The output can be seen at this url also: https://jsonplaceholder.typicode.com/users
Now in this json array I need to pick 1 record at a time, insert that into DB.
I tried pass output of HTTP 'Body' to JsonParse().
I also tried pass output of HTTP 'Body' to Initialize variable and then foreach control but no success.
If you are using the HTTP action to get the json value, you don't need to parse it to json, the output supports select property.
And in my test I could get the value, so I believe you used a wrong expression. Cause the json items are stored as array, so you need pick the index firstly then select the property. You could use body('HTTP')[1]['name'] to get property value, and if you want to get a item just delete name with body('HTTP')[1] to implement it.
Without property, just pick the second item.

JSON to SQL Server 2016 missing rows from array

I am new to getting JSON into SQL Server 2016, I thought I had it down, but I notice that I am missing some details from the array, looking at the image, there are four address', but I saw there are some more address' missing for example Burrows Rd, and Urana RD. How can I make sure that all the address' captured?
https://i.stack.imgur.com/erzBV.jpg
#json nvarchar(max)
#json = N'{
"response": [
{
"application": {
"info": {
"dat_id": "010.2018.00036494.001",
"development_type": "Residential - Single new dwelling",
"application_type": "DA",
"last_modified_date": "2018-12-03T11:35:24+11:00",
"description": "Residence, Garage & Colorbond Shed, Demolition of Existing Residence & Tree Removal",
"authority": {
"ref": "http://gemini:82/ApplicationTracker/atdis/1.0",
"name": "AlburyCity"
},
"lodgement_date": "2018-10-26T00:00:00+11:00",
"determination_date": null,
"determination_type": "Pending",
"status": "In Progress",
"notification_start_date": null,
"notification_end_date": null,
"officer": "David Flood",
"estimated_cost": "Not applicable.",
"related_apps": [ ]
},
"reference": {
"more_info_url": "http://gemini:82/ApplicationTracker/Application/ApplicationDetails/010.2018.00036494.001/",
"comments_url": null
},
"locations": [
{
"land_title_ref": {
"torrens": {
"lot": "11",
"section": null,
"dpsp_id": "DP 1031272"
}
},
"address": {
"street": "680 Centaur RD",
"suburb": "HAMILTON VALLEY",
"state": "NSW",
"postcode": "2641"
},
"geometry": null
},
{
"land_title_ref": {
"torrens": {
"lot": "11",
"section": null,
"dpsp_id": "DP 1031272"
}
},
"address": {
"street": "Urana RD",
"suburb": "HAMILTON VALLEY",
"state": "NSW",
"postcode": "2641"
},
"geometry": null
},
{
"land_title_ref": {
"torrens": {
"lot": "11",
"section": null,
"dpsp_id": "DP 1031272"
}
},
"address": {
"street": "Burrows RD",
"suburb": "HAMILTON VALLEY",
"state": "NSW",
"postcode": "2641"
},
"geometry": null
}
],
"events": [
{
"id": "3680347",
"timestamp": "2018-11-01T15:58:00+11:00",
"description": "Public Notification",
"event_type": "PNOT",
"status": "COMP"
},
{
"id": "3680348",
"timestamp": "2018-11-01T15:58:00+11:00",
"description": "Referral Engineering",
"event_type": "ENG",
"status": "COMP"
},
{
"id": "3680349",
"timestamp": "2018-11-01T15:59:00+11:00",
"description": "Referal Parks & Recreation",
"event_type": "TREE",
"status": "COMP"
},
{
"id": "3680350",
"timestamp": "2018-11-01T16:00:00+11:00",
"description": "Acknowledgement to Applicant",
"event_type": "ACKN",
"status": "COMP"
},
{
"id": "3683617",
"timestamp": "2018-11-21T14:59:00+11:00",
"description": "Site Assessment Inspection",
"event_type": "SITE",
"status": "PASS"
},
{
"id": "3685155",
"timestamp": "2018-12-03T11:37:00+11:00",
"description": "Assessment Report",
"event_type": "ASS3",
"status": "COMP"
}
],
"documents": [
{
"ref": "DOC18/163129",
"title": "Statement of Environmental Effects - SEE",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=6hF7YEiv0qE=&fileName=Statement+of+Environmental+Effects+-+SEE.PDF"
},
{
"ref": "DOC18/163139",
"title": "Site Plan and Elevations",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=1Gv3GVOIHCM=&fileName=Site+Plan+and+Elevations.PDF"
}
],
"people": [
{
"name": "Karyn Ford",
"role": "Applicant",
"contact": "6023 8287"
}
],
"extended": {
"software_vendor": "Civica",
"software_vendor_url": "http://www.civica.com.au"
}
}
},
{
"application": {
"info": {
"dat_id": "017.2018.00036017.001",
"development_type": "Subdivision Only",
"application_type": "SCC",
"last_modified_date": "2018-12-03T10:19:25+11:00",
"description": "Roads, Sewer, Water & Drainage for Two (2) Lot Torrens Title Subdivisi on",
"authority": {
"ref": "http://gemini:82/ApplicationTracker/atdis/1.0",
"name": "AlburyCity"
},
"lodgement_date": "2018-11-14T00:00:00+11:00",
"determination_date": "2018-11-29T00:00:00+11:00",
"determination_type": "Approved under delegation",
"status": "Determined",
"notification_start_date": null,
"notification_end_date": null,
"officer": "Sharna Holland",
"estimated_cost": "Not applicable.",
"related_apps": [ "http://gemini:82/ApplicationTracker/atdis/1.0/010.2018.00036017.001.json" ]
},
"reference": {
"more_info_url": "http://gemini:82/ApplicationTracker/Application/ApplicationDetails/017.2018.00036017.001/",
"comments_url": null
},
"locations": [
{
"land_title_ref": {
"torrens": {
"lot": "A",
"section": null,
"dpsp_id": "DP 161410"
}
},
"address": {
"street": "419 Hovell ST",
"suburb": "SOUTH ALBURY",
"state": "NSW",
"postcode": "2640"
},
"geometry": null
},
{
"land_title_ref": {
"torrens": {
"lot": "A",
"section": null,
"dpsp_id": "DP 161410"
}
},
"address": {
"street": "Charles ST",
"suburb": "SOUTH ALBURY",
"state": "NSW",
"postcode": "2640"
},
"geometry": null
}
],
"events": [
{
"id": "3683888",
"timestamp": "2018-11-23T14:03:00+11:00",
"description": "Acknowledgement to Applicant",
"event_type": "ACKN",
"status": "COMP"
},
{
"id": "3683902",
"timestamp": "2018-11-23T15:21:00+11:00",
"description": "Referral Engineering",
"event_type": "ENG",
"status": "COMP"
},
{
"id": "3683903",
"timestamp": "2018-11-23T15:21:00+11:00",
"description": "Referral Building Surveyor 3",
"event_type": "BS3",
"status": "COMP"
},
{
"id": "3683904",
"timestamp": "2018-11-23T15:21:00+11:00",
"description": "Referral Trainee Town Planner",
"event_type": "TTP1",
"status": "COMP"
},
{
"id": "3684791",
"timestamp": "2018-11-29T14:36:00+11:00",
"description": "Collected Determination",
"event_type": "COLL",
"status": "COMP"
}
],
"documents": [
{
"ref": "DOC18/177392",
"title": "Subdivision Works Certificate",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=8qU1Pkawfvg=&fileName=Subdivision+Works+Certificate.PDF"
}
],
"people": [
{
"name": "Eslers Land Consulting",
"role": "Applicant",
"contact": "6021 1322"
}
],
"extended": {
"software_vendor": "Civica",
"software_vendor_url": "http://www.civica.com.au"
}
}
},
{
"application": {
"info": {
"dat_id": "010.2016.00034838.001",
"development_type": "Residential - New multi unit",
"application_type": "DA",
"last_modified_date": "2018-12-03T09:36:09+11:00",
"description": "Twenty (20) Detached Self Contained Residences - Kensington Gardens Retirement Village",
"authority": {
"ref": "http://gemini:82/ApplicationTracker/atdis/1.0",
"name": "AlburyCity"
},
"lodgement_date": "2016-08-17T00:00:00+10:00",
"determination_date": "2016-10-24T00:00:00+11:00",
"determination_type": "Approved under delegation",
"status": "Determined",
"notification_start_date": null,
"notification_end_date": null,
"officer": "Christopher Eldred",
"estimated_cost": "Not applicable.",
"related_apps": [ "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.001.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.002.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.003.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.004.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.005.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.006.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.007.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.008.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.009.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.010.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.011.json", "http://gemini:82/ApplicationTracker/atdis/1.0/011.2016.00034838.012.json" ]
},
"reference": {
"more_info_url": "http://gemini:82/ApplicationTracker/Application/ApplicationDetails/010.2016.00034838.001/",
"comments_url": null
},
"locations": [
{
"land_title_ref": {
"torrens": {
"lot": "2",
"section": null,
"dpsp_id": "DP 874732"
}
},
"address": {
"street": "100 Table Top RD",
"suburb": "THURGOONA",
"state": "NSW",
"postcode": "2640"
},
"geometry": null
}
],
"events": [
{
"id": "3583145",
"timestamp": "2016-08-17T14:13:00+10:00",
"description": "Further Information Requested",
"event_type": "INFO",
"status": "COMP"
},
{
"id": "3573096",
"timestamp": "2016-08-18T15:34:00+10:00",
"description": "Public Notification",
"event_type": "PNOT",
"status": "COMP"
},
{
"id": "3573097",
"timestamp": "2016-08-18T15:37:00+10:00",
"description": "Referral Building Surveyor 2",
"event_type": "BS2",
"status": "COMP"
},
{
"id": "3573098",
"timestamp": "2016-08-18T15:37:00+10:00",
"description": "Referral Plumbing Inspector",
"event_type": "PI",
"status": "COMP"
},
{
"id": "3573099",
"timestamp": "2016-08-18T15:37:00+10:00",
"description": "Referral Engineering",
"event_type": "ENG",
"status": "COMP"
},
{
"id": "3573100",
"timestamp": "2016-08-18T15:38:00+10:00",
"description": "Referral Environmental Planner",
"event_type": "ENV",
"status": "COMP"
},
{
"id": "3573103",
"timestamp": "2016-08-18T15:43:43+10:00",
"description": "Acknowledgement to Applicant",
"event_type": "ACKN",
"status": "COMP"
},
{
"id": "3575194",
"timestamp": "2016-09-06T00:00:00+10:00",
"description": "Assessment Report",
"event_type": "ASS3",
"status": "COMP"
}
],
"documents": [
{
"ref": "DOC16/209893",
"title": "Statement of Environmental Effects - SEE",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=sQkVV9rEsTU=&fileName=Statement+of+Environmental+Effects+-+SEE.PDF"
},
{
"ref": "DOC16/209896",
"title": "Site Plan & Elevations",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=3dRqEZHzGeo=&fileName=Site+Plan+%26+Elevations.PDF"
},
{
"ref": "DOC16/211819",
"title": "Assessment Report",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=DVTQkQQqbns=&fileName=Assessment+Report.PDF"
},
{
"ref": "DOC16/240764",
"title": "Development Consent",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=TY+Y3zjyDKw=&fileName=Development+Consent.PDF"
}
],
"people": [
{
"name": "Kensington Gardens Lifestyle Estates",
"role": "Applicant",
"contact": "6049 3100"
}
],
"extended": {
"software_vendor": "Civica",
"software_vendor_url": "http://www.civica.com.au"
}
}
},
{
"application": {
"info": {
"dat_id": "010.2018.00036468.001",
"development_type": "Residential - Single new dwelling",
"application_type": "DA",
"last_modified_date": "2018-11-30T17:17:25+11:00",
"description": "Residence, Garage and Retaining Walls",
"authority": {
"ref": "http://gemini:82/ApplicationTracker/atdis/1.0",
"name": "AlburyCity"
},
"lodgement_date": "2018-10-19T00:00:00+11:00",
"determination_date": "2018-11-26T00:00:00+11:00",
"determination_type": "Approved under delegation",
"status": "Determined",
"notification_start_date": null,
"notification_end_date": null,
"officer": "David Flood",
"estimated_cost": "Not applicable.",
"related_apps": [ "http://gemini:82/ApplicationTracker/atdis/1.0/011.2018.00036468.001.json" ]
},
"reference": {
"more_info_url": "http://gemini:82/ApplicationTracker/Application/ApplicationDetails/010.2018.00036468.001/",
"comments_url": null
},
"locations": [
{
"land_title_ref": {
"torrens": {
"lot": "218",
"section": null,
"dpsp_id": "DP 1228226"
}
},
"address": {
"street": "20 Stockman CRCT",
"suburb": "THURGOONA",
"state": "NSW",
"postcode": "2640"
},
"geometry": null
}
],
"events": [
{
"id": "3678966",
"timestamp": "2018-10-25T10:47:00+11:00",
"description": "Public Notification",
"event_type": "PNOT",
"status": "COMP"
},
{
"id": "3678967",
"timestamp": "2018-10-25T10:48:00+11:00",
"description": "Referral Engineering",
"event_type": "ENG",
"status": "COMP"
},
{
"id": "3678974",
"timestamp": "2018-10-25T10:51:00+11:00",
"description": "Acknowledgement to Applicant",
"event_type": "ACKN",
"status": "COMP"
},
{
"id": "3681955",
"timestamp": "2018-11-01T15:49:00+11:00",
"description": "Site Assessment Inspection",
"event_type": "SITE",
"status": "COMP"
},
{
"id": "3684251",
"timestamp": "2018-11-27T10:24:00+11:00",
"description": "Collected Determination",
"event_type": "COLL",
"status": "COMP"
}
],
"documents": [
{
"ref": "DOC18/159026",
"title": "Statement of Environmental Effects - SEE",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=MaiWkTs8V+g=&fileName=Statement+of+Environmental+Effects+-+SEE.PDF"
},
{
"ref": "DOC18/159033",
"title": "Site Plan and Elevations and Superseded Plan",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=2xpqra8gNb0=&fileName=Site+Plan+and+Elevations+and+Superseded+Plan.PDF"
},
{
"ref": "DOC18/162569",
"title": "Assessment Report - Bldg Residential",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=bKYCMP01aJE=&fileName=Assessment+Report+-+Bldg+Residential.PDF"
},
{
"ref": "DOC18/168584",
"title": "Development Consent",
"document_url": "http://gemini:82/ApplicationTracker/atdis/1.0/Document/Download?key=SxGG/yKi68s=&fileName=Development+Consent.PDF"
}
],
"people": [
{
"name": "Alatalo Bros",
"role": "Applicant",
"contact": "02 6055 0180"
}
],
"extended": {
"software_vendor": "Civica",
"software_vendor_url": "http://www.civica.com.au"
}
}
}
],
"count": 4,
"pagination": {
"previous": null,
"next": 2,
"current": 1,
"per_page": 4,
"count": 24091,
"pages": 6023
}
}'
select *
from OPENJSON(#json, '$.response')
with
([lot] varchar(200) '$.application.locations[0].land_title_ref.torrens.lot',
[section] varchar(200) '$.application.locations[0].land_title_ref.torrens.section',
[dpsp_id] varchar(200) '$.application.locations[0].land_title_ref.torrens.dpsp_id',
[Street] varchar(200) '$.application.locations[0].address.street',
[suburb] varchar(200) '$.application.locations[0].address.suburb',
[state] varchar(200) '$.application.locations[0].address.state',
[postcode] varchar(200) '$.application.locations[0].address.postcode',
[geometry] varchar(200) '$.application.locations[0].geometry'
)
Try this:
select L.*
from OPENJSON(#json,'$.response') R
CROSS APPLY OPENJSON(R.[value], '$.application.locations')
with
(
[lot] varchar(200) '$.land_title_ref.torrens.lot',
[section] varchar(200) '$.land_title_ref.torrens.section',
[dpsp_id] varchar(200) '$.land_title_ref.torrens.dpsp_id',
[Street] varchar(200) '$.address.street',
[suburb] varchar(200) '$.address.suburb',
[state] varchar(200) '$.address.state',
[postcode] varchar(200) '$.address.postcode',
[geometry] varchar(200) '$.geometry'
) L
The locations is an array, so we need to use cross apply and OPENSJON to get all elements.

elasticsearch ngrams results are wrong

I am trying to implement partial matching using ngrams in elasticsearch but not getting the expected results out of it.
I am following this link:-
https://www.elastic.co/guide/en/elasticsearch/guide/current/_index_time_search_as_you_type.html
I have done all the things which are mentioned in this link. My dataset contains 3 fields i.e id,name,age.
Here is my mapping and setting of my_index
GET /my_index/_settings
{
"my_index": {
"settings": {
"index": {
"creation_date": "1433249154544",
"uuid": "hKxHVnqaRVmji31xK92pVA",
"number_of_replicas": "1",
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": "1",
"max_gram": "20"
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"filter": [
"lowercase",
"autocomplete_filter"
],
"tokenizer": "standard"
}
}
},
"number_of_shards": "1",
"version": {
"created": "1040499"
}
}
}
}
}
GET /my_index/_mapping/my_type
{
"my_index": {
"mappings": {
"my_type": {
"properties": {
"#timestamp": {
"type": "date",
"format": "dateOptionalTime"
},
"#version": {
"type": "string"
},
"age": {
"type": "long"
},
"host": {
"type": "string"
},
"id": {
"type": "string"
},
"message": {
"type": "string"
},
"name": {
"type": "string",
"index_analyzer": "autocomplete",
"search_analyzer": "standard"
},
"path": {
"type": "string"
},
"type": {
"type": "string"
}
}
}
}
}
}
My query to elastic search is :-
GET /my_index/my_type/_search
{
"query": {
"match": {
"name": {
"query": "raman r"
}
}
}
}
According to me now the results should display only "raman ram" but it is also showing other results as well:-
{
"took": 13,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 9,
"max_score": 2.6631343,
"hits": [
{
"_index": "my_index",
"_type": "my_type",
"_id": "2",
"_score": 2.6631343,
"_source": {
"message": [
"2,raman,23"
],
"#version": "1",
"#timestamp": "2015-06-02T13:07:18.041Z",
"type": "my_type",
"host": "shubham-VirtualBox",
"path": "/home/shubham/sample.csv",
"id": "2",
"name": "raman",
"age": 23
}
},
{
"_index": "my_index",
"_type": "my_type",
"_id": "10",
"_score": 1.8003473,
"_source": {
"message": [
"10,raman ram,43"
],
"#version": "1",
"#timestamp": "2015-06-02T13:11:03.455Z",
"type": "my_type",
"host": "shubham-VirtualBox",
"path": "/home/shubham/sample.csv",
"id": "10",
"name": "raman ram",
"age": 43
}
},
{
"_index": "my_index",
"_type": "my_type",
"_id": "1",
"_score": 0.26245093,
"_source": {
"message": [
"1,Ram,342"
],
"#version": "1",
"#timestamp": "2015-06-02T13:07:18.040Z",
"type": "my_type",
"host": "shubham-VirtualBox",
"path": "/home/shubham/sample.csv",
"id": "1",
"name": "Ram",
"age": 342
}
},
{
"_index": "my_index",
"_type": "my_type",
"_id": "3",
"_score": 0.26245093,
"_source": {
"message": [
"3,ramayan,23"
],
"#version": "1",
"#timestamp": "2015-06-02T13:07:18.041Z",
"type": "my_type",
"host": "shubham-VirtualBox",
"path": "/home/shubham/sample.csv",
"id": "3",
"name": "ramayan",
"age": 23
}
},
{
"_index": "my_index",
"_type": "my_type",
"_id": "4",
"_score": 0.26245093,
"_source": {
"message": [
"4,ramaram,231"
],
"#version": "1",
"#timestamp": "2015-06-02T13:07:18.041Z",
"type": "my_type",
"host": "shubham-VirtualBox",
"path": "/home/shubham/sample.csv",
"id": "4",
"name": "ramaram",
"age": 231
}
},
{
"_index": "my_index",
"_type": "my_type",
"_id": "5",
"_score": 0.26245093,
"_source": {
"message": [
"5,rampy,1"
],
"#version": "1",
"#timestamp": "2015-06-02T13:07:18.041Z",
"type": "my_type",
"host": "shubham-VirtualBox",
"path": "/home/shubham/sample.csv",
"id": "5",
"name": "rampy",
"age": 1
}
},
{
"_index": "my_index",
"_type": "my_type",
"_id": "6",
"_score": 0.26245093,
"_source": {
"message": [
"6,ration,11"
],
"#version": "1",
"#timestamp": "2015-06-02T13:07:18.041Z",
"type": "my_type",
"host": "shubham-VirtualBox",
"path": "/home/shubham/sample.csv",
"id": "6",
"name": "ration",
"age": 11
}
},
{
"_index": "my_index",
"_type": "my_type",
"_id": "7",
"_score": 0.26245093,
"_source": {
"message": [
"7,rita,42"
],
"#version": "1",
"#timestamp": "2015-06-02T13:07:18.042Z",
"type": "my_type",
"host": "shubham-VirtualBox",
"path": "/home/shubham/sample.csv",
"id": "7",
"name": "rita",
"age": 42
}
},
{
"_index": "my_index",
"_type": "my_type",
"_id": "8",
"_score": 0.26245093,
"_source": {
"message": [
"8,roni,45"
],
"#version": "1",
"#timestamp": "2015-06-02T13:07:18.050Z",
"type": "my_type",
"host": "shubham-VirtualBox",
"path": "/home/shubham/sample.csv",
"id": "8",
"name": "roni",
"age": 45
}
}
]
}
}
I get correct results when i use "minimum_should_match": "100%" while querying.
GET /my_index/my_type/_search
{
"query": {
"match": {
"name": {
"query": "raman r",
"minimum_should_match": "100%"
}
}
}
}
Gave me better result although ranking is not right:
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 2.6631343,
"hits": [
{
"_index": "my_index",
"_type": "my_type",
"_id": "2",
"_score": 2.6631343,
"_source": {
"message": [
"2,raman,23"
],
"#version": "1",
"#timestamp": "2015-06-02T13:07:18.041Z",
"type": "my_type",
"host": "shubham-VirtualBox",
"path": "/home/shubham/sample.csv",
"id": "2",
"name": "raman",
"age": 23
}
},
{
"_index": "my_index",
"_type": "my_type",
"_id": "10",
"_score": 1.8003473,
"_source": {
"message": [
"10,raman ram,43"
],
"#version": "1",
"#timestamp": "2015-06-02T13:11:03.455Z",
"type": "my_type",
"host": "shubham-VirtualBox",
"path": "/home/shubham/sample.csv",
"id": "10",
"name": "raman ram",
"age": 43
}
}
]
}
}
Don't know whether this approach is correct or not but do tell me if any alternative is there for this

Resources