Jsonpath. Sum by another value - jsonpath

can jsonpath sum by another value? I would to have sums by category.
{
"category": "reference",
"price": 8.95,
},
{
"category": "reference",
"price": 12.99,
},
{
"category": "fiction",
"price": 8.99,
},
{
"category": "fiction",
"price": 22.99,
}
I expect
{
"category": "reference",
"sum": 21.94,
},
{
"category": "fiction",
"sum": 31.98,
}
or
{
"fiction": 31.98,
"reference": 21.94,
}
I think it's impossible but I hope I mistake

Related

Here Waypoint Sequencing API Doesn't Honor Delivery Windows

I am experimenting with the HERE Waypoint Sequencing API using the new JSON request format, and it doesn't seem to take into account delivery windows specified in the times array within the plan object. I went back to the example provided in the documentation and found that the same thing was happening: Arrival and departure times are far from the specified delivery windows.
In my Example, Customer 1 has times:
"times": [["2020-07-04T08:00:00Z","2020-07-04T10:00:00Z"],["2020-07-04T16:00:00Z","2020-07-04T18:00:00Z"]]
However, the solution contains:
"time": {
"arrival": "2020-07-04T00:30:00.000+0000",
"departure": "2020-07-04T00:33:00.000+0000"
}
Which isn't even close.
Endpoint: https://wps.hereapi.com/v8/findsequence
Request:
{
"configuration": {
"optimizations": {
"traffic": "liveOrHistorical",
"waitingTime": {
"bufferTime": 15,
"reduce": false
}
}
},
"fleet": {
"profiles": [{"type":"car","name":"normal_car"}],
"types": [
{
"amount": 1,
"capacity": [10,5],
"costs": {
"distance": 0.0001,
"fixed": 22,
"time": 0.0048
},
"id": "string",
"limits": {
"maxDistance": 20000,
"shiftTime": 21600
},
"profile": "normal_car",
"shifts": [
{
"breaks": [
{
"duration": 180,
"location": {
"lat": 52.53088,
"lng": 13.38471
},
"times": [["2020-07-04T08:00:00Z","2020-07-04T10:00:00Z"],["2020-07-04T16:00:00Z","2020-07-04T18:00:00Z"]]
}
],
"end": {
"location": {
"lat": 52.53088,
"lng": 13.38471
},
"time": "2020-07-04T23:30:00Z"
},
"start": {
"location": {
"lat": 52.53088,
"lng": 13.38471
},
"time": "2020-07-04T00:30:00Z"
}
}
],
"skills": ["fridge"]
}
]
},
"id": "7f3423c2-784a-4983-b472-e14107d5a54a",
"plan": {
"jobs": [
{
"id": "string",
"places": {
"deliveries": [
{
"demand": [10,5],
"duration": 180,
"location": {
"lat": 52.53088,
"lng": 13.38471
},
"tag": "Customer 1",
"times": [["2020-07-04T08:00:00Z","2020-07-04T10:00:00Z"],["2020-07-04T16:00:00Z","2020-07-04T18:00:00Z"]]
},
{
"demand": [10,5],
"duration": 180,
"location": {
"lat": 53.53088,
"lng": 14.98471
},
"tag": "Customer 2",
"times": [["2020-07-04T08:00:00Z","2020-07-04T10:00:00Z"],["2020-07-04T16:00:00Z","2020-07-04T18:00:00Z"]]
}
],
"pickups": [
{
"demand": [10,5],
"duration": 180,
"location": {
"lat": 52.53088,
"lng": 13.98471
},
"tag": "some_tag",
"times": [["2020-07-04T08:00:00Z","2020-07-04T10:00:00Z"],["2020-07-04T16:00:00Z","2020-07-04T18:00:00Z"]]
}
]
},
"skills": ["fridge"]
}
],
"relations": [
{
"jobs": [
"string"
],
"type": "flexible",
"vehicleId": "7f3423c2-784a-4983-b472-e14107d5a54a"
}
]
}
}
Response:
{
"problemId": "7f3423c2-784a-4983-b472-e14107d5a54a",
"statistic": {
"cost": null,
"distance": 441655,
"duration": 20127,
"times": {
"break": 0,
"driving": 19587,
"serving": 540,
"waiting": 0
}
},
"tours": [
{
"vehicleId": "string",
"typeId": null,
"stops": [
{
"location": {
"lat": 52.53088,
"lng": 13.38471
},
"time": {
"arrival": null,
"departure": "2020-07-04T00:30:00.000+0000"
},
"load": [
],
"activities": [
{
"jobId": "departure",
"jobTag": "departure",
"type": null,
"location": null,
"time": null
}
]
},
{
"location": {
"lat": 52.53088,
"lng": 13.38471
},
"time": {
"arrival": "2020-07-04T00:30:00.000+0000",
"departure": "2020-07-04T00:33:00.000+0000"
},
"load": [
],
"activities": [
{
"jobId": "Customer 1",
"jobTag": "Customer 1",
"type": null,
"location": null,
"time": null
}
]
},
{
"location": {
"lat": 52.53088,
"lng": 13.98471
},
"time": {
"arrival": "2020-07-04T01:34:05.000+0000",
"departure": "2020-07-04T01:37:05.000+0000"
},
"load": [
],
"activities": [
{
"jobId": "some_tag",
"jobTag": "some_tag",
"type": null,
"location": null,
"time": null
}
]
},
{
"location": {
"lat": 53.53088,
"lng": 14.98471
},
"time": {
"arrival": "2020-07-04T03:53:37.000+0000",
"departure": "2020-07-04T03:56:37.000+0000"
},
"load": [
],
"activities": [
{
"jobId": "Customer 2",
"jobTag": "Customer 2",
"type": null,
"location": null,
"time": null
}
]
},
{
"location": {
"lat": 52.53088,
"lng": 13.38471
},
"time": {
"arrival": "2020-07-04T06:05:27.000+0000",
"departure": null
},
"load": [
],
"activities": [
{
"jobId": "arrival",
"jobTag": "arrival",
"type": null,
"location": null,
"time": null
}
]
}
],
"statistic": {
"cost": null,
"distance": 441655,
"duration": 20127,
"times": {
"break": 0,
"driving": 19587,
"serving": 540,
"waiting": 0
}
}
}
],
"unassigned": null
}
Am I missing something?

Address in autocomplete results

When I do an autosuggest request in the address response I only receive the label. The address object is not filled.
This is my request: https://autosuggest.search.hereapi.com/v1/autosuggest?at=48.8578817,2.2791249999999934&limit=5&q=stj&apikey=xxxx
I receive this:
"title": "Top Services (Stj)",
"id": "here:pds:place:250u09wj-afceace0a11b49bca950ea22d0f8e452",
"resultType": "place",
"address": {
"label": "********"
},
I will need to receive the formatted address without the name
How can I fix this?
thanks
We have tried to reproduce your query and it works for us, please see the following code.
Please review the documentation page for detailed information on autosuggest
Documentation link :
https://autosuggest.search.hereapi.com/v1/autosuggest?at=48.8578817,2.2791249999999934&limit=5&q=stj&apikey=XXXX.
Query Result:
{
"items": [
{
"title": "Top Services (Stj)",
"id": "here:pds:place:250u09wj-afceace0a11b49bca950ea22d0f8e452",
"resultType": "place",
"address": {
"label": "Top Services, 61 Rue du Faubourg Saint-Denis, 75010 Paris, France"
},
"position": {
"lat": 48.8721,
"lng": 2.35384
},
"access": [
{
"lat": 48.87208,
"lng": 2.35392
}
],
"distance": 5690,
"categories": [
{
"id": "700-7200-0254",
"name": "Construction",
"primary": true
},
{
"id": "700-7200-0264",
"name": "Services de conseil et de gestion"
},
{
"id": "700-7200-0277",
"name": "Entrepreneur de second œuvre"
}
],
"highlights": {
"title": [
{
"start": 14,
"end": 17
}
],
"address": {
"label": [
]
}
}
},
{
"title": "La Clinique du Scooter d'Occasion (Stj 2 Roues)",
"id": "here:pds:place:250u09tv-591de1b090c54199b11154a72f462c0d",
"resultType": "place",
"address": {
"label": "La Clinique du Scooter d'Occasion, 148 Boulevard du Montparnasse, 75014 Paris, France"
},
"position": {
"lat": 48.84039,
"lng": 2.33383
},
"access": [
{
"lat": 48.84052,
"lng": 2.33393
}
],
"distance": 4451,
"categories": [
{
"id": "400-4200-0241",
"name": "Services logistiques",
"primary": true
}
],
"highlights": {
"title": [
{
"start": 35,
"end": 38
}
],
"address": {
"label": [
]
}
}
},
{
"title": "Stjohn's",
"id": "here:pds:place:2501r4ve-43f913ba8f9b0e7046aaee61bcfe8b9b",
"resultType": "place",
"address": {
"label": "Stjohn's, 11 Rue Edmond Valentin, 75007 Paris, France"
},
"position": {
"lat": 48.85961,
"lng": 2.30159
},
"access": [
{
"lat": 48.85968,
"lng": 2.30157
}
],
"distance": 1655,
"categories": [
{
"id": "700-7400-0141",
"name": "Services aux entreprises",
"primary": true
},
{
"id": "700-7200-0252",
"name": "Publicité, marketing, communication et études de marché"
}
],
"highlights": {
"title": [
{
"start": 0,
"end": 3
}
],
"address": {
"label": [
{
"start": 0,
"end": 3
}
]
}
}
},
{
"title": "Stjohn S",
"id": "here:pds:place:250u09tv-0f38e06dd8634ab4a0d931dad94de24c",
"resultType": "place",
"address": {
"label": "Stjohn S, 4 Rue des Petits-Pères, 75002 Paris, France"
},
"position": {
"lat": 48.86601,
"lng": 2.34027
},
"access": [
{
"lat": 48.8662,
"lng": 2.34023
}
],
"distance": 4564,
"categories": [
{
"id": "700-7200-0252",
"name": "Publicité, marketing, communication et études de marché",
"primary": true
},
{
"id": "700-7200-0271",
"name": "Services financiers et d'assurance"
}
],
"highlights": {
"title": [
{
"start": 0,
"end": 3
}
],
"address": {
"label": [
{
"start": 0,
"end": 3
}
]
}
}
},
{
"title": "Espace St-Jo'",
"id": "here:pds:place:250u09te-220742c64e4a40a48b8772987e7f987c",
"resultType": "place",
"address": {
"label": "Espace St-Jo', 54 Rue du Moulin de Pierres, 92140 Clamart, France"
},
"position": {
"lat": 48.80865,
"lng": 2.26594
},
"access": [
{
"lat": 48.8087,
"lng": 2.2659
}
],
"distance": 5558,
"categories": [
{
"id": "200-2200-0000",
"name": "Théâtre, musique et culture",
"primary": true
},
{
"id": "200-2000-0015",
"name": "Salle de spectacle/concert"
},
{
"id": "550-5520-0000",
"name": "Aire de loisirs"
}
],
"references": [
{
"supplier": {
"id": "yelp"
},
"id": "xJtl5krT8OZ3QYXtMl6Leg"
}
],
"highlights": {
"title": [
{
"start": 7,
"end": 12
}
],
"address": {
"label": [
{
"start": 7,
"end": 12
}
]
}
}
}
],
"queryTerms": [
]
}

Why is averageRating always 0?

I am using the 'Explore Popular Places by Category' API and it always returns averageRating as 0 for all items in the result.
I made this call with various categories such as restaurants and sights-museums, but it always returns 0 for averageRating. Does HERE not provide this detail, and if so, why is it returned in the response?
Some details:
I am making a call to this url:
https://places.ls.hereapi.com/places/v1/discover/explore?at=52.5159%2C13.3777&cat=sights-museums&apiKey={api_key}
and it returns something like this:
{
"results": {
"next": "https://places.ls.hereapi.com/places/v1/discover/explore;context=Y2F0PXNpZ2h0cy1tdXNldW1zJmZsb3ctaWQ9Mjk0ZjU1NTgtMmY0Mi01Y2FiLWJlYWUtOGEyM2ViY2EzMzgzXzE1ODMyNjMyNjEwMzZfMF84NTcyJm9mZnNldD0yMCZzaXplPTIw?at=52.5159%2C13.3777&app_id=LKO34glU2MBEVbcOD5mQ&app_code=A2ta_nQ8HRYwenju5HFG5Q",
"items": [
{
"position": [
52.51629,
13.37817
],
"distance": 54,
"title": "Brandenburg Gate",
"averageRating": 0,
"category": {
"id": "landmark-attraction",
"title": "Landmark/Attraction",
"href": "https://places.ls.hereapi.com/places/v1/categories/places/landmark-attraction?app_id=LKO34glU2MBEVbcOD5mQ&app_code=A2ta_nQ8HRYwenju5HFG5Q",
"type": "urn:nlp-types:category",
"system": "places"
},
"icon": "https://download.vcdn.data.here.com/p/d/places2/icons/categories/38.icon",
"vicinity": "Pariser Platz<br/>Mitte, 10117 Berlin",
"having": [],
"type": "urn:nlp-types:place",
"href": "https://places.ls.hereapi.com/places/v1/places/276u33db-8ee2e0de906e459cbade0593986debe9;context=Zmxvdy1pZD0yOTRmNTU1OC0yZjQyLTVjYWItYmVhZS04YTIzZWJjYTMzODNfMTU4MzI2MzI2MTAzNl8wXzg1NzImcmFuaz0w?app_id=LKO34glU2MBEVbcOD5mQ&app_code=A2ta_nQ8HRYwenju5HFG5Q",
"id": "276u33db-8ee2e0de906e459cbade0593986debe9",
"alternativeNames": [
{
"name": "Brandenburger Tor",
"language": "de"
}
]
},
{
"position": [
52.51373,
13.37976
],
"distance": 279,
"title": "Holocaust Memorial",
"averageRating": 0,
"category": {
"id": "museum",
"title": "Museum",
"href": "https://places.ls.hereapi.com/places/v1/categories/places/museum?app_id=LKO34glU2MBEVbcOD5mQ&app_code=A2ta_nQ8HRYwenju5HFG5Q",
"type": "urn:nlp-types:category",
"system": "places"
},
"icon": "https://download.vcdn.data.here.com/p/d/places2/icons/categories/10.icon",
"vicinity": "Cora-Berliner-Straße 1<br/>Mitte, 10117 Berlin",
"having": [],
"type": "urn:nlp-types:place",
"href": "https://places.ls.hereapi.com/places/v1/places/276u33de-df7d57fd38494a93b2018fe549a0fd75;context=Zmxvdy1pZD0yOTRmNTU1OC0yZjQyLTVjYWItYmVhZS04YTIzZWJjYTMzODNfMTU4MzI2MzI2MTAzNl8wXzg1NzImcmFuaz0x?app_id=LKO34glU2MBEVbcOD5mQ&app_code=A2ta_nQ8HRYwenju5HFG5Q",
"id": "276u33de-df7d57fd38494a93b2018fe549a0fd75",
"openingHours": {
"text": "Tue-Sun: 10:00 - 20:00",
"label": "Opening hours",
"isOpen": false,
"structured": [
{
"start": "T100000",
"duration": "PT10H00M",
"recurrence": "FREQ:DAILY;BYDAY:TU,WE,TH,FR,SA,SU"
}
]
},
"alternativeNames": [
{
"name": "Memorial to the Murdered European Jews",
"language": "en"
},
{
"name": "Memorial to the Murdered Jews of Europe",
"language": "en"
},
{
"name": "Denkmal für die ermordeten Juden Europas",
"language": "de"
}
]
},
{
"position": [
52.51666,
13.40784
],
"distance": 2041,
"title": "Nicholas Quarter",
"averageRating": 0,
"category": {
"id": "museum",
"title": "Museum",
"href": "https://places.ls.hereapi.com/places/v1/categories/places/museum?app_id=LKO34glU2MBEVbcOD5mQ&app_code=A2ta_nQ8HRYwenju5HFG5Q",
"type": "urn:nlp-types:category",
"system": "places"
},
"icon": "https://download.vcdn.data.here.com/p/d/places2/icons/categories/10.icon",
"vicinity": "Nikolaikirchplatz<br/>Mitte, 10178 Berlin",
"having": [],
"type": "urn:nlp-types:place",
"href": "https://places.ls.hereapi.com/places/v1/places/276u33dc-049683d3c6be4bdba823808678a1b164;context=Zmxvdy1pZD0yOTRmNTU1OC0yZjQyLTVjYWItYmVhZS04YTIzZWJjYTMzODNfMTU4MzI2MzI2MTAzNl8wXzg1NzImcmFuaz0xOQ?app_id=LKO34glU2MBEVbcOD5mQ&app_code=A2ta_nQ8HRYwenju5HFG5Q",
"id": "276u33dc-049683d3c6be4bdba823808678a1b164",
"alternativeNames": [
{
"name": "Nikolaiviertel",
"language": "en"
},
{
"name": "Nikolaiviertel",
"language": "de"
}
]
}
]
},
"search": {
"context": {
"location": {
"position": [
52.5159,
13.3777
],
"address": {
"text": "Ebertstraße 22<br/>Mitte, 10117 Berlin<br/>Germany",
"house": "22",
"street": "Ebertstraße",
"postalCode": "10117",
"district": "Mitte",
"city": "Berlin",
"county": "Berlin",
"stateCode": "Berlin",
"country": "Germany",
"countryCode": "DEU"
}
},
"type": "urn:nlp-types:place",
"href": "https://places.ls.hereapi.com/places/v1/places/loc-dmVyc2lvbj0xO3RpdGxlPUViZXJ0c3RyYSVDMyU5RmUrMjI7bGF0PTUyLjUxNTk7bG9uPTEzLjM3Nzc7c3RyZWV0PUViZXJ0c3RyYSVDMyU5RmU7aG91c2U9MjI7Y2l0eT1CZXJsaW47cG9zdGFsQ29kZT0xMDExNztjb3VudHJ5PURFVTtkaXN0cmljdD1NaXR0ZTtzdGF0ZUNvZGU9QmVybGluO2NvdW50eT1CZXJsaW47Y2F0ZWdvcnlJZD1idWlsZGluZztzb3VyY2VTeXN0ZW09aW50ZXJuYWw;context=c2VhcmNoQ29udGV4dD0x?app_id=LKO34glU2MBEVbcOD5mQ&app_code=A2ta_nQ8HRYwenju5HFG5Q"
}
}
}
Does HERE not provide the averageRatings of restaurants or sights-museums?
From the docs it appears if the place hasn't received a rating it'll be 0
Note: If the place has no ratings (yet), both the average and the count values are zero. But if the place cannot be rated (i.e. a street), the whole rating object is not present.
https://developer.here.com/documentation/places/dev_guide/topics/object-rating.html

How can I write a query that looks in all array entries?

How do I write a CosmosDB query or SPR that allows me to look for an entry in all entries in an array? where each array entry is a complex datatype and not just a simple array?
I have tried using this query:
SELECT DISTINCT c.locales[0].categories[0] AS topLevelCategory
FROM c
WHERE c.locales[0].country = 'SE'
The problem is that I cannot gurantee that c.loclales[0] is always 'SE' some times that is the second or third entry in the array so I dont know what c.locales[X] should be where X represents the locale I need, for example if c.locales[0] is 'SE' then I wont get the hit I want because 'SE' happens to be c.locales[1]
How can get around this limitation? I need to be able to first apply the country = 'SE' to get the correct array entry and then after that get the categories from that array entry.
I just cannot figure out how this can be done?
Sample document below and expected output would be
"Herr" in whatever output format is easiest.
{
"id": "0570eca0-8f16-4c85-a985-e3a271bcc6bc",
"_id": "5b07c2bfbc7407000122e8b4",
"artno": "0614460008",
"vendor": "Acme",
"updatedAt": "2019-06-25T18:50:33.167Z",
"locales": [
{
"title": "Gestreiftes T-Shirt",
"description": "Gestreiftes T-Shirt aus Baumwolljersey.",
"categories": [
"Herren",
"Große Größen",
"T-Shirts & Tanktops",
"T-Shirt"
],
"brand": null,
"images": [
],
"country": "DE",
"currency": "EUR",
"language": "de",
"variants": [
{
"artno": "0614460008005",
"urls": [
],
"price": 9.99,
"stock": 1,
"attributes": {
"size": "XL",
"color": "Schwarz/Weiß gestreift"
}
},
{
"artno": "0614460008002",
"urls": [
],
"price": 9.99,
"stock": 1,
"attributes": {
"size": "S",
"color": "Schwarz/Weiß gestreift"
}
},
{
"artno": "0614460008004",
"urls": [
],
"price": 9.99,
"stock": 1,
"attributes": {
"size": "L",
"color": "Schwarz/Weiß gestreift"
}
},
{
"artno": "0614460008001",
"urls": [
],
"price": 9.99,
"stock": 1,
"attributes": {
"size": "XS",
"color": "Schwarz/Weiß gestreift"
}
},
{
"artno": "0614460008006",
"urls": [
],
"price": 9.99,
"stock": 1,
"attributes": {
"size": "XXL",
"color": "Schwarz/Weiß gestreift"
}
},
{
"artno": "0614460008003",
"urls": [
],
"price": 9.99,
"stock": 1,
"attributes": {
"size": "M",
"color": "Schwarz/Weiß gestreift"
}
}
]
},
{
"title": "Striped T-shirt",
"description": "Striped T-shirt in cotton jersey.",
"categories": [
"Men",
"T-shirts & Vests",
"Short Sleeve",
"T-shirt"
],
"brand": null,
"images": [
],
"country": "UK",
"currency": "GBP",
"language": "en",
"variants": [
{
"artno": "0614460008006",
"urls": [
],
"price": 8.99,
"stock": 1,
"attributes": {
"size": "XXL",
"color": "Black/White striped"
}
},
{
"artno": "0614460008005",
"urls": [
],
"price": 8.99,
"stock": 1,
"attributes": {
"size": "XL",
"color": "Black/White striped"
}
},
{
"artno": "0614460008004",
"urls": [
],
"price": 8.99,
"stock": 1,
"attributes": {
"size": "L",
"color": "Black/White striped"
}
},
{
"artno": "0614460008002",
"urls": [
],
"price": 8.99,
"stock": 1,
"attributes": {
"size": "S",
"color": "Black/White striped"
}
},
{
"artno": "0614460008003",
"urls": [
],
"price": 8.99,
"stock": 1,
"attributes": {
"size": "M",
"color": "Black/White striped"
}
},
{
"artno": "0614460008001",
"urls": [
],
"price": 8.99,
"stock": 1,
"attributes": {
"size": "XS",
"color": "Black/White striped"
}
}
]
},
{
"title": "Randig t-shirt",
"description": "En randig t-shirt i bomullstrikå.",
"categories": [
"Herr",
"T-shirts & Linnen",
"Kortärmat",
"T-shirt"
],
"brand": null,
"images": [
],
"country": "SE",
"currency": "SEK",
"language": "sv",
"variants": [
{
"artno": "0614460008001",
"urls": [
],
"price": 99,
"stock": 1,
"attributes": {
"size": "XS",
"color": "Svart/Vitrandig"
}
},
{
"artno": "0614460008001",
"urls": [
],
"price": 99,
"stock": 1,
"attributes": {
"size": "XL",
"color": "Svart/Vitrandig"
}
},
{
"artno": "0614460008001",
"urls": [
],
"price": 99,
"stock": 1,
"attributes": {
"size": "S",
"color": "Svart/Vitrandig"
}
},
{
"artno": "0614460008001",
"urls": [
],
"price": 99,
"stock": 1,
"attributes": {
"size": "XXL",
"color": "Svart/Vitrandig"
}
},
{
"artno": "0614460008001",
"urls": [
],
"price": 99,
"stock": 1,
"attributes": {
"size": "M",
"color": "Svart/Vitrandig"
}
},
{
"artno": "0614460008001",
"urls": [
],
"price": 99,
"stock": 1,
"attributes": {
"size": "L",
"color": "Svart/Vitrandig"
}
}
]
},
{
"title": "Striped T-shirt",
"description": "Striped T-shirt in cotton jersey.",
"categories": [
"Men",
"T-shirts & Tank tops",
"Short Sleeves",
"T-shirt"
],
"brand": null,
"images": [
],
"country": "US",
"currency": "USD",
"language": "en",
"variants": [
{
"artno": "0614460008001",
"urls": [
],
"price": 9.99,
"stock": 0,
"attributes": {
"size": "S",
"color": "Black/white striped"
}
},
{
"artno": "0614460008001",
"urls": [
],
"price": 9.99,
"stock": 0,
"attributes": {
"size": "XL",
"color": "Black/white striped"
}
},
{
"artno": "0614460008001",
"urls": [
],
"price": 9.99,
"stock": 0,
"attributes": {
"size": "M",
"color": "Black/white striped"
}
},
{
"artno": "0614460008001",
"urls": [
],
"price": 9.99,
"stock": 0,
"attributes": {
"size": "L",
"color": "Black/white striped"
}
},
{
"artno": "0614460008001",
"urls": [
],
"price": 9.99,
"stock": 0,
"attributes": {
"size": "XXL",
"color": "Black/white striped"
}
},
{
"artno": "0614460008001",
"urls": [
],
"price": 9.99,
"stock": 1,
"attributes": {
"size": "XS",
"color": "Black/white striped"
}
}
]
}
],
"relatedArtno": [
"0614460001",
"0614460002",
"0614460005",
"0614460006",
"0614460007",
"0614460011",
"0614460012"
],
"_rid": "QEwcAMCVWqgGAAAAAAAAAA==",
"_self": "dbs/QEwcAA==/colls/QEwcAMCVWqg=/docs/QEwcAMCVWqgGAAAAAAAAAA==/",
"_etag": "\"2e00f1ca-0000-0c00-0000-5d144d660000\"",
"_attachments": "attachments/",
"_ts": 1561611622
}
Use Join in your sql:
SELECT locales.categories[0] AS topLevelCategory
FROM c
join locales in c.locales
WHERE locales.country = 'SE'
Output:
Update Answer:
Two points.
One,your locales is also an array so you can't access categories with c.locales.categories.You need to query categories using c.locales[index].categories.
Two,Array_contains has third param. If you want to filter array with partial conditions,you need to add third param as false.
ARRAY_CONTAINS(c.locales[index].categories[0], 'kids',true)
More details,please refer to the document.

Can I adjust this query to only show the relevant locale?

I have a query that
SELECT c
FROM c
join locales in c.locales
WHERE locales.country = 'SE' AND
locales.language = 'sv' AND
locales.categories[0] = 'Dam'
I am trying to adjust it to only display the relevant locale as specified in the WHERE clause so I tried adjusting it to:
SELECT c.locales[0]
FROM c
join locales in c.locales
WHERE locales.country = 'SE' AND
locales.language = 'sv' AND
locales.categories[0] = 'Dam'
But that does not help since it might not be locales[0], I had assumed that the join would make the relevant part of the array always appear as index [0] but I was wrong
How can I adjust the query to show the entire document but only the relevant part in the locales array?
Please note I want the entire document shown but only with the relevant locale from that array.
The documents looks as below:
{
"id": "0570eca0-8f16-4c85-a985-e3a271bcc6bc",
"_id": "5b07c2bfbc7407000122e8b4",
"artno": "0614460008",
"vendor": "Acme",
"updatedAt": "2019-06-25T18:50:33.167Z",
"locales": [
{
"title": "Gestreiftes T-Shirt",
"description": "Gestreiftes T-Shirt aus Baumwolljersey.",
"categories": [
"Herren",
"Große Größen",
"T-Shirts & Tanktops",
"T-Shirt"
],
"brand": null,
"images": [
],
"country": "DE",
"currency": "EUR",
"language": "de",
"variants": [
{
"artno": "0614460008005",
"urls": [
],
"price": 9.99,
"stock": 1,
"attributes": {
"size": "XL",
"color": "Schwarz/Weiß gestreift"
}
},
{
"artno": "0614460008002",
"urls": [
],
"price": 9.99,
"stock": 1,
"attributes": {
"size": "S",
"color": "Schwarz/Weiß gestreift"
}
},
{
"artno": "0614460008004",
"urls": [
],
"price": 9.99,
"stock": 1,
"attributes": {
"size": "L",
"color": "Schwarz/Weiß gestreift"
}
},
{
"artno": "0614460008001",
"urls": [
],
"price": 9.99,
"stock": 1,
"attributes": {
"size": "XS",
"color": "Schwarz/Weiß gestreift"
}
},
{
"artno": "0614460008006",
"urls": [
],
"price": 9.99,
"stock": 1,
"attributes": {
"size": "XXL",
"color": "Schwarz/Weiß gestreift"
}
},
{
"artno": "0614460008003",
"urls": [
],
"price": 9.99,
"stock": 1,
"attributes": {
"size": "M",
"color": "Schwarz/Weiß gestreift"
}
}
]
},
{
"title": "Striped T-shirt",
"description": "Striped T-shirt in cotton jersey.",
"categories": [
"Men",
"T-shirts & Vests",
"Short Sleeve",
"T-shirt"
],
"brand": null,
"images": [
],
"country": "UK",
"currency": "GBP",
"language": "en",
"variants": [
{
"artno": "0614460008006",
"urls": [
],
"price": 8.99,
"stock": 1,
"attributes": {
"size": "XXL",
"color": "Black/White striped"
}
},
{
"artno": "0614460008005",
"urls": [
],
"price": 8.99,
"stock": 1,
"attributes": {
"size": "XL",
"color": "Black/White striped"
}
},
{
"artno": "0614460008004",
"urls": [
],
"price": 8.99,
"stock": 1,
"attributes": {
"size": "L",
"color": "Black/White striped"
}
},
{
"artno": "0614460008002",
"urls": [
],
"price": 8.99,
"stock": 1,
"attributes": {
"size": "S",
"color": "Black/White striped"
}
},
{
"artno": "0614460008003",
"urls": [
],
"price": 8.99,
"stock": 1,
"attributes": {
"size": "M",
"color": "Black/White striped"
}
},
{
"artno": "0614460008001",
"urls": [
],
"price": 8.99,
"stock": 1,
"attributes": {
"size": "XS",
"color": "Black/White striped"
}
}
]
},
{
"title": "Randig t-shirt",
"description": "En randig t-shirt i bomullstrikå.",
"categories": [
"Herr",
"T-shirts & Linnen",
"Kortärmat",
"T-shirt"
],
"brand": null,
"images": [
],
"country": "SE",
"currency": "SEK",
"language": "sv",
"variants": [
{
"artno": "0614460008001",
"urls": [
],
"price": 99,
"stock": 1,
"attributes": {
"size": "XS",
"color": "Svart/Vitrandig"
}
},
{
"artno": "0614460008001",
"urls": [
],
"price": 99,
"stock": 1,
"attributes": {
"size": "XL",
"color": "Svart/Vitrandig"
}
},
{
"artno": "0614460008001",
"urls": [
],
"price": 99,
"stock": 1,
"attributes": {
"size": "S",
"color": "Svart/Vitrandig"
}
},
{
"artno": "0614460008001",
"urls": [
],
"price": 99,
"stock": 1,
"attributes": {
"size": "XXL",
"color": "Svart/Vitrandig"
}
},
{
"artno": "0614460008001",
"urls": [
],
"price": 99,
"stock": 1,
"attributes": {
"size": "M",
"color": "Svart/Vitrandig"
}
},
{
"artno": "0614460008001",
"urls": [
],
"price": 99,
"stock": 1,
"attributes": {
"size": "L",
"color": "Svart/Vitrandig"
}
}
]
},
{
"title": "Striped T-shirt",
"description": "Striped T-shirt in cotton jersey.",
"categories": [
"Men",
"T-shirts & Tank tops",
"Short Sleeves",
"T-shirt"
],
"brand": null,
"images": [
],
"country": "US",
"currency": "USD",
"language": "en",
"variants": [
{
"artno": "0614460008001",
"urls": [
],
"price": 9.99,
"stock": 0,
"attributes": {
"size": "S",
"color": "Black/white striped"
}
},
{
"artno": "0614460008001",
"urls": [
],
"price": 9.99,
"stock": 0,
"attributes": {
"size": "XL",
"color": "Black/white striped"
}
},
{
"artno": "0614460008001",
"urls": [
],
"price": 9.99,
"stock": 0,
"attributes": {
"size": "M",
"color": "Black/white striped"
}
},
{
"artno": "0614460008001",
"urls": [
],
"price": 9.99,
"stock": 0,
"attributes": {
"size": "L",
"color": "Black/white striped"
}
},
{
"artno": "0614460008001",
"urls": [
],
"price": 9.99,
"stock": 0,
"attributes": {
"size": "XXL",
"color": "Black/white striped"
}
},
{
"artno": "0614460008001",
"urls": [
],
"price": 9.99,
"stock": 1,
"attributes": {
"size": "XS",
"color": "Black/white striped"
}
}
]
}
],
"relatedArtno": [
"0614460001",
"0614460002",
"0614460005",
"0614460006",
"0614460007",
"0614460011",
"0614460012"
],
"_rid": "QEwcAMCVWqgGAAAAAAAAAA==",
"_self": "dbs/QEwcAA==/colls/QEwcAMCVWqg=/docs/QEwcAMCVWqgGAAAAAAAAAA==/",
"_etag": "\"2e00f1ca-0000-0c00-0000-5d144d660000\"",
"_attachments": "attachments/",
"_ts": 1561611622
}
Matt. According to your description, i think you could make a slight change as below:
SELECT locales
FROM c
join locales in c.locales
WHERE locales.country = 'SE' AND
locales.language = 'sv' AND
locales.categories[0] = 'Herr'
Output:
Update sql:
SELECT c.id,c.artno,c.XXX(what properties you want),.....
,locales
FROM c
join locales in c.locales
WHERE locales.country = 'SE' AND
locales.language = 'sv' AND
locales.categories[0] = 'Herr'

Resources