Sparql Group Entire Objects into List - sparql

I have a list of restaurants and want to return them grouped in lists by two identifiers. The response would look this this in JSON:
[
{
"restaurantChainId": "1",
"restaurantTypeId": "001",
"restaurantList": [
{
"restaurantId": "1-1",
"restaurantChainId": "1",
"restaurantTypeId": "001",
"restaurant name": "Pizza Place London"
"restaurant location": "London"
},
{
"restaurantId": "1-2",
"restaurantChainId": "1",
"restaurantTypeId": "001",
"restaurant name": "Pizza Place Birmingham"
"restaurant location": "Birmingham"
}
]
},
{
"restaurantChainId": "1",
"restaurantTypeId": "002",
"restaurantList": [
{
"restaurantId": "1-3",
"restaurantChainId": "1",
"restaurantTypeId": "002",
"restaurant name": "Pizza Place Manchester"
"restaurant location": "Manchester"
}
]
},
{
"restaurantChainId": "2",
"restaurantTypeId": "002",
"restaurantList": [
{
"restaurantId": "2-1",
"restaurantChainId": "2",
"restaurantTypeId": "002",
"restaurant name": "Taco Town London"
"restaurant location": "London"
},
{
"restaurantId": "2-2",
"restaurantChainId": "2",
"restaurantTypeId": "002",
"restaurant name": "Taco Town Newcastle"
"restaurant location": "Newcastle"
}
]
}
]
So that an object in the array has a list where each in the list shares the restaurantChainId and the restaurantTypeId.
I have tried the following group_concat query:
SELECT ?restaurantChainId (GROUP_CONCAT(?restaurantTypeId; SEPARATOR=", ") AS ?restaurantTypeIdList)
WHERE {
?restaurant <http://example.com/terms#docType> "restaurant" ;
<http://example.com/terms#restaurantTypeId> ?restaurantTypeId;
<http://example.com/terms#institutionFid> ?restaurantChainId .
FILTER (strstarts(str(?restaurantTypeId), '00'))
} GROUP BY ?restaurantChainId
But obviously this is just producing a list restaurantTypeId for each restaurantChainId. So it has grouped things correctly. I have things in the correct groups but I only have the id list for each restaurant where I actually want all related information of that restaurant. I don't really know how to go about this. Is it possible?
Improved Query
SELECT ?restaurantChainId (GROUP_CONCAT(DISTINCT ?restaurantTypeId; SEPARATOR=", ") AS ?restaurantTypeIdList) (GROUP_CONCAT(?restaurant; SEPARATOR=", ") AS ?restaurant)
WHERE {
?restaurant <http://example.co.uk/terms#docType> "restaurant" ;
<http://example.co.uk/terms#swiftbic> ?restaurantTypeId;
<http://example.co.uk/terms#institutionFid> ?restaurantChainId ;
<http://example.co.uk/terms#fid> ?officeId .
FILTER (strstarts(str(?restaurantTypeId), 'ABA'))
} GROUP BY ?restaurantChainId ?restaurantTypeId
And here is the current result:
{
"head" : {
"vars" : [ "restaurantChainId", "restaurantTypeIdList", "restaurant" ]
},
"results" : {
"bindings" : [ {
"restaurantChainId" : {
"type" : "literal",
"value" : "XYZ"
},
"restaurantTypeIdList" : {
"type" : "literal",
"value" : "ABA3"
},
"restaurant" : {
"type" : "literal",
"value" : "http://example.co.uk/restaurant/XYZ-4, http://example.co.uk/restaurant/XYZ-5, http://example.co.uk/restaurant/XYZ-6"
}
}, {
"restaurantChainId" : {
"type" : "literal",
"value" : "ABC"
},
"restaurantTypeIdList" : {
"type" : "literal",
"value" : "ABA1"
},
"restaurant" : {
"type" : "literal",
"value" : "http://example.co.uk/restaurant/ABC-14, http://example.co.uk/restaurant/ABC-15, http://example.co.uk/restaurant/ABC-4"
}
}, {
"restaurantChainId" : {
"type" : "literal",
"value" : "XYZ"
},
"restaurantTypeIdList" : {
"type" : "literal",
"value" : "ABA1"
},
"restaurant" : {
"type" : "literal",
"value" : "http://example.co.uk/restaurant/XYZ-2, http://example.co.uk/restaurant/XYZ-1"
}
}, {
"restaurantChainId" : {
"type" : "literal",
"value" : "XYZ"
},
"restaurantTypeIdList" : {
"type" : "literal",
"value" : "ABA2"
},
"restaurant" : {
"type" : "literal",
"value" : "http://example.co.uk/restaurant/XYZ-3"
}
}, {
"restaurantChainId" : {
"type" : "literal",
"value" : "ABC"
},
"restaurantTypeIdList" : {
"type" : "literal",
"value" : "ABA2"
},
"restaurant" : {
"type" : "literal",
"value" : "http://example.co.uk/restaurant/ABC-9"
}
} ]
}
}
So the actually groupings are correct and I have the uri for each restaurant but I don't know how to get information specifically related to them.

Related

How do i change MongoDB JSON data to array

I need to update the MongoDB field with the array of objects where JSON object to be updated with as an array
if I have something like this in MongoDB
"designSectionContents" : [
{
"_id" : "5bae17ecbd7595540145ec98",
"type" : "subSection",
"columns" : [
{
"0" : {
"itemId" : "5b7465980783d9a37058f160",
"type" : "field"
}
},
{
"0" : {
"itemId" : "5b7465630783d9a37058f15c",
"type" : "field"
}
},
{
"0" : {
"itemId" : "5b7465810783d9a37058f15e",
"type" : "field"
}
}
],
"subSectionContentLayout" : {
"labelPlacement" : "Top",
"columns" : 3
}
}
]
I want to change the above snippet to below in MongoDB
"designSectionContents" : [
{
"_id" : ObjectId("5bae17ecbd7595540145ec98"),
"type" : "subSection",
"columns" : [
[
{
"itemId" : "5b7465980783d9a37058f160",
"type" : "field"
}
],
[
{
"itemId" : "5b7465630783d9a37058f15c",
"type" : "field"
}
],
[
{
"itemId" : "5b7465810783d9a37058f15e",
"type" : "field"
}
]
]
}
]
curly braces opening and closing tag has to be changed to array
This should work:
db.collection.aggregate([
{
"$project": {
"designSectionContents": {
"$map": {
"input": "$designSectionContents",
"as": "designSectionContent",
"in": {
"_id": "$$designSectionContent._id",
"type": "$$designSectionContent.type",
"columns": {
"$map": {
"input": "$$designSectionContent.columns",
"as": "inp",
"in": [
"$$inp.0"
]
}
}
}
}
}
}
}
]);
Here's the working link.

How to guarantee air price quote after PNR creation on Sabre API?

I'm trying to create a PNR with "Time to think/Fare lock" option offered by airlines like AF, KLM, LH and more. The idea is to create the PNR to temporarily "block" the price until the time limit is reached (48~72hs) but I don't know how.
I'm able to create the PNR, with CreatePassengerNameRecord, without problems and it returns the retained PriceQuote but the fare is not guaranteed until ticketed and the system will re-price the itinerary with the current fare before ticketing.
Request/response example
CreatePassengerNameRecordRQ
"CreatePassengerNameRecordRQ" : {
"version" : "2.2.0",
"haltOnAirPriceError" : true,
"TravelItineraryAddInfo" : {
"AgencyInfo" : {
"Address" : {
"AddressLine" : "TEST",
"CityName" : "TEST",
"CountryCode" : "FR",
"PostalCode" : "99999",
"StreetNmbr" : "TEST 123"
},
"Ticketing" : {
"PseudoCityCode" : "L4GJ",
"TicketType" : "7TAW"
}
},
"CustomerInfo" : {
"ContactNumbers" : {
"ContactNumber" : [
{
"Phone" : "99999999",
"PhoneUseType" : "A"
}
]
},
"CustLoyalty" : [],
"Email" : [
{
"Address" : "test#gmail.com"
},
{
"Address" : "testRes#gmail.com"
}
],
"PersonName" : [
{
"NameNumber" : "1.1",
"PassengerType" : "ADT",
"GivenName" : "TEST",
"Surname" : "TEST"
}
]
}
},
"AirBook" : {
"HaltOnStatus" : [
{
"Code" : "HL"
},
{
"Code" : "KK"
},
{
"Code" : "LL"
},
{
"Code" : "NN"
},
{
"Code" : "NO"
},
{
"Code" : "UC"
},
{
"Code" : "US"
}
],
"OriginDestinationInformation" : {
"FlightSegment" : [
{
"DepartureDateTime" : "2021-02-17T13:15:00",
"ArrivalDateTime" : "2021-02-17T13:45:00",
"FlightNumber" : "1780",
"NumberInParty" : "1",
"ResBookDesigCode" : "G",
"Status" : "NN",
"DestinationLocation" : {
"LocationCode" : "LHR"
},
"MarketingAirline" : {
"Code" : "AF",
"FlightNumber" : "1780"
},
"OriginLocation" : {
"LocationCode" : "CDG"
}
},
{
"DepartureDateTime" : "2021-02-26T11:30:00",
"ArrivalDateTime" : "2021-02-26T13:50:00",
"FlightNumber" : "1581",
"NumberInParty" : "1",
"ResBookDesigCode" : "X",
"Status" : "NN",
"DestinationLocation" : {
"LocationCode" : "CDG"
},
"MarketingAirline" : {
"Code" : "AF",
"FlightNumber" : "1581"
},
"OriginLocation" : {
"LocationCode" : "LHR"
}
}
]
}
},
"AirPrice" : [
{
"PriceComparison" : {
"AcceptablePriceDecrease" : {
"Amount" : 125.3,
"HaltOnNonAcceptablePrice" : true
},
"AcceptablePriceIncrease" : {
"Amount" : 5,
"HaltOnNonAcceptablePrice" : true
},
"AmountSpecified" : 125.3
},
"PriceRequestInformation" : {
"Retain" : true,
"OptionalQualifiers" : {
"MiscQualifiers" : {
"BaggageAllowance" : []
},
"FOP_Qualifiers" : {
"BasicFOP" : {
"Type" : "CK"
}
},
"PricingQualifiers" : {
"ItineraryOptions" : {
"SegmentSelect" : [
{
"Number" : "1",
"RPH" : "1"
},
{
"Number" : "2",
"RPH" : "2"
}
]
},
"PassengerType" : [
{
"Quantity" : "1",
"Code" : "ADT"
}
],
"SpecificFare" : [
{
"FareBasis" : "GS50OALG",
"RPH" : "1"
},
{
"FareBasis" : "XS50OALG",
"RPH" : "2"
}
]
}
}
}
}
],
"SpecialReqDetails" : {
"SpecialService" : {
"SpecialServiceInfo" : {
"AdvancePassenger" : [],
"SecureFlight" : [
{
"PersonName" : {
"NameNumber" : "1.1",
"DateOfBirth" : "1991-01-13",
"Gender" : "M",
"GivenName" : "TEST",
"Surname" : "TEST"
}
}
],
"Service" : [
{
"SSR_Code" : "CTCM",
"PersonName" : {
"NameNumber" : "1.1"
},
"Text" : "0033142890939"
},
{
"SSR_Code" : "CTCE",
"PersonName" : {
"NameNumber" : "1.1"
},
"Text" : "TEST"
}
]
}
}
},
"PostProcessing" : {
"RedisplayReservation" : {
"waitInterval" : 1000
},
"EndTransaction" : {
"Email" : {
"eTicket" : {
"PDF" : {
"Ind" : false
},
"Ind" : false
},
"Ind" : true
},
"Source" : {
"ReceivedFrom" : "TEST"
}
}
}
}
}
CreatePassengerNameRecordRS (partial)
"CreatePassengerNameRecordRS" : {
"ApplicationResults" : {
"status" : "Complete",
"Success" : [
{
"timeStamp" : "2020-11-19T06:29:15.342-06:00"
}
],
"Warning" : [
{
"type" : "BusinessLogic",
"timeStamp" : "2020-11-19T06:29:14.016-06:00",
"SystemSpecificResults" : [
{
"Message" : [
{
"code" : "WARN.SWS.HOST.WARNING_RESPONSE",
"content" : "EndTransactionLLSRQ: TTY REQ PEND"
}
]
}
]
}
]
},
"ItineraryRef" : {
"ID" : "HOKJCQ"
},
"AirBook" : {
"OriginDestinationOption" : {
"FlightSegment" : [
{
"ArrivalDateTime" : "02-17T13:45",
"DepartureDateTime" : "02-17T13:15",
"eTicket" : true,
"FlightNumber" : "1780",
"NumberInParty" : "001",
"ResBookDesigCode" : "G",
"Status" : "NN",
"DestinationLocation" : {
"LocationCode" : "LHR"
},
"MarketingAirline" : {
"Code" : "AF",
"FlightNumber" : "1780"
},
"OriginLocation" : {
"LocationCode" : "CDG"
}
},
{
"ArrivalDateTime" : "02-26T13:50",
"DepartureDateTime" : "02-26T11:30",
"eTicket" : true,
"FlightNumber" : "1581",
"NumberInParty" : "001",
"ResBookDesigCode" : "X",
"Status" : "NN",
"DestinationLocation" : {
"LocationCode" : "CDG"
},
"MarketingAirline" : {
"Code" : "AF",
"FlightNumber" : "1581"
},
"OriginLocation" : {
"LocationCode" : "LHR"
}
}
]
}
},
"AirPrice" : [
{
"PriceComparison" : {
"AmountReturned" : "125.30",
"AmountSpecified" : "125.3"
},
"PriceQuote" : {
"MiscInformation" : {
"BaggageInfo" : {
"SubCodeProperties" : [
{
"SolutionSequenceNmbr" : 1,
"RPH" : 1,
"AncillaryFeeGroupCode" : "BG",
"CommercialNameofBaggageItemType" : "FREE BAGGAGE ALLOWANCE",
"EMD_Type" : "4",
"ExtendedSubCodeKey" : "0DFAAAF"
},
{
"SolutionSequenceNmbr" : 1,
"RPH" : 2,
"AncillaryFeeGroupCode" : "BG",
"CommercialNameofBaggageItemType" : "UPTO50LB 23KG AND62LI 158LCM",
"DescriptionOne" : {
"Code" : "23",
"Text" : "UP TO 50 POUNDS/23 KILOGRAMS"
},
"DescriptionTwo" : {
"Code" : "6U",
"Text" : "UP TO 62 LINEAR INCHES/158 LINEAR CENTIMETERS"
},
"EMD_Type" : "4",
"ExtendedSubCodeKey" : "0GOACAF",
"SizeWeightInfo" : {
"MaximumSizeInAlternate" : {
"Units" : "C",
"content" : "158"
},
"MaximumSize" : {
"Units" : "I",
"content" : "62"
},
"MaximumWeightInAlternate" : {
"Units" : "K",
"content" : "23"
},
"MaximumWeight" : {
"Units" : "L",
"content" : "50"
}
}
},
{
"SolutionSequenceNmbr" : 1,
"RPH" : 3,
"AncillaryFeeGroupCode" : "BG",
"AncillaryService" : {
"SubGroupCode" : "CY",
"Text" : "CARRY ON HAND BAGGAGE"
},
"CommercialNameofBaggageItemType" : "CARRYON HAND BAGGAGE ALLOWANCE",
"EMD_Type" : "4",
"ExtendedSubCodeKey" : "0LNABAF"
},
{
"SolutionSequenceNmbr" : 1,
"RPH" : 4,
"AncillaryFeeGroupCode" : "BG",
"AncillaryService" : {
"SubGroupCode" : "CY",
"Text" : "CARRY ON HAND BAGGAGE"
},
"BookingMethod" : "04",
"CommercialNameofBaggageItemType" : "CABIN BAGGAGE 12KG 1PC 115CM",
"DescriptionOne" : {
"Code" : "12",
"Text" : "UP TO 26 POUNDS/12 KILOGRAMS"
},
"DescriptionTwo" : {
"Code" : "4U",
"Text" : "UP TO 45 LINEAR INCHES/115 LINEAR CENTIMETERS"
},
"EMD_Type" : "4",
"ExtendedSubCodeKey" : "0MRACAF",
"SizeWeightInfo" : {
"MaximumSizeInAlternate" : {
"Units" : "C",
"content" : "115"
},
"MaximumSize" : {
"Units" : "I",
"content" : "45"
},
"MaximumWeightInAlternate" : {
"Units" : "K",
"content" : "12"
},
"MaximumWeight" : {
"Units" : "L",
"content" : "26"
}
}
}
]
},
"HeaderInformation" : [
{
"SolutionSequenceNmbr" : "1",
"DepartureDate" : "2021-02-17",
"Text" : [
"VALIDATING CARRIER - AF",
"CAT 15 SALES RESTRICTIONS FREE TEXT FOUND - VERIFY RULES",
"BAG ALLOWANCE -CDGLHR-NIL/AF",
"1STCHECKED BAG FEE-CDGLHR-EUR45.00/AF/UP TO 50 POUNDS/23 KILOGR",
"AMS AND UP TO 62 LINEAR INCHES/158 LINEAR CENTIMETERS",
"2NDCHECKED BAG FEE-CDGLHR-EUR70.00/AF/UP TO 50 POUNDS/23 KILOGR",
"AMS AND UP TO 62 LINEAR INCHES/158 LINEAR CENTIMETERS",
"BAG ALLOWANCE -LHRCDG-NIL/AF",
"1STCHECKED BAG FEE-LHRCDG-EUR45.00/AF/UP TO 50 POUNDS/23 KILOGR",
"AMS AND UP TO 62 LINEAR INCHES/158 LINEAR CENTIMETERS",
"2NDCHECKED BAG FEE-LHRCDG-EUR70.00/AF/UP TO 50 POUNDS/23 KILOGR",
"AMS AND UP TO 62 LINEAR INCHES/158 LINEAR CENTIMETERS",
"CARRY ON ALLOWANCE",
"CDGLHR LHRCDG-01P/AF",
"01/UP TO 26 POUNDS/12 KILOGRAMS AND UP TO 45 LINEAR INCHES/115",
"LINEAR CENTIMETERS",
"CARRY ON CHARGES",
"CDGLHR LHRCDG-AF-CARRY ON FEES UNKNOWN-CONTACT CARRIER",
"ADDITIONAL ALLOWANCES AND/OR DISCOUNTS MAY APPLY DEPENDING ON",
"FLYER-SPECIFIC FACTORS /E.G. FREQUENT FLYER STATUS/MILITARY/",
"CREDIT CARD FORM OF PAYMENT/EARLY PURCHASE OVER INTERNET,ETC./"
],
"ValidatingCarrier" : {
"Code" : "AF"
}
}
],
"SolutionInformation" : [
{
"SolutionSequenceNmbr" : "1",
"BaseFareCurrencyCode" : "EUR",
"CurrencyCode" : "EUR",
"GrandTotalEquivFareAmount" : "34.00",
"GrandTotalTaxes" : "91.30",
"RequiresRebook" : "false",
"TicketNumber" : "0",
"TotalAmount" : "125.30"
}
],
"ValidatingCarrier" : [
{
"NewValidatingProcess" : true,
"SolutionSequenceNmbr" : "1",
"SettlementMethod" : "BSP",
"Ticket" : [
{
"Type" : "ETKTREQ",
"CarrierCode" : "AF",
"ValidatingCarrierType" : "Default"
}
]
}
]
},
"PricedItinerary" : {
"AlternativePricing" : "false",
"CurrencyCode" : "EUR",
"MultiTicket" : false,
"TotalAmount" : "125.30",
"AirItineraryPricingInfo" : [
{
"SolutionSequenceNmbr" : "1",
"BaggageProvisions" : [
...
],
"FareCalculation" : {
"Text" : "PAR AF LON17.62AF PAR22.33NUC39.95END ROE0.85086"
},
"FareCalculationBreakdown" : [
{
"Branch" : {
"PCC" : "N1GJ",
"FirstJointCarrier" : "AF"
},
"Departure" : {
"CityCode" : "PAR",
"AirportCode" : "CDG",
"AirlineCode" : "AF",
"GenericInd" : "O",
"ArrivalCityCode" : "LON",
"ArrivalAirportCode" : "LHR"
},
"FareBasis" : {
"Code" : "GS50OALG",
"FareAmount" : "17.62",
"FarePassengerType" : "ADT",
"FareType" : "P",
"FilingCarrier" : "AF",
"GlobalInd" : "EH",
"TripTypeInd" : "R",
"Market" : "PARLON",
"Cabin" : "Y"
},
"FreeBaggageAllowance" : "NONIL",
"RuleCategoryIndicator" : [
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"15",
"16"
]
},
{
"Branch" : {
"PCC" : "N1GJ",
"FirstJointCarrier" : "AF"
},
"Departure" : {
"CityCode" : "LON",
"AirportCode" : "LHR",
"AirlineCode" : "AF",
"GenericInd" : "O",
"ArrivalCityCode" : "PAR",
"ArrivalAirportCode" : "CDG"
},
"FareBasis" : {
"Code" : "XS50OALG",
"FareAmount" : "22.33",
"FarePassengerType" : "ADT",
"FareType" : "P",
"FilingCarrier" : "AF",
"GlobalInd" : "EH",
"TripTypeInd" : "R",
"Market" : "PARLON",
"Cabin" : "Y"
},
"FreeBaggageAllowance" : "NONIL",
"RuleCategoryIndicator" : [
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"15",
"16"
]
}
],
"ItinTotalFare" : {
"NonRefundableInd" : "N",
"BaggageInfo" : {
"NonUS_DOT_Disclosure" : {
"Text" : [
"BAG ALLOWANCE -CDGLHR-NIL/AF",
"1STCHECKED BAG FEE-CDGLHR-EUR45.00/AF/UP TO 50 POUNDS/23 KILOGR",
"AMS AND UP TO 62 LINEAR INCHES/158 LINEAR CENTIMETERS",
"2NDCHECKED BAG FEE-CDGLHR-EUR70.00/AF/UP TO 50 POUNDS/23 KILOGR",
"AMS AND UP TO 62 LINEAR INCHES/158 LINEAR CENTIMETERS",
"BAG ALLOWANCE -LHRCDG-NIL/AF",
"1STCHECKED BAG FEE-LHRCDG-EUR45.00/AF/UP TO 50 POUNDS/23 KILOGR",
"AMS AND UP TO 62 LINEAR INCHES/158 LINEAR CENTIMETERS",
"2NDCHECKED BAG FEE-LHRCDG-EUR70.00/AF/UP TO 50 POUNDS/23 KILOGR",
"AMS AND UP TO 62 LINEAR INCHES/158 LINEAR CENTIMETERS",
"CARRY ON ALLOWANCE",
"CDGLHR LHRCDG-01P/AF",
"01/UP TO 26 POUNDS/12 KILOGRAMS AND UP TO 45 LINEAR INCHES/115",
"LINEAR CENTIMETERS",
"CARRY ON CHARGES",
"CDGLHR LHRCDG-AF-CARRY ON FEES UNKNOWN-CONTACT CARRIER",
"ADDITIONAL ALLOWANCES AND/OR DISCOUNTS MAY APPLY DEPENDING ON",
"FLYER-SPECIFIC FACTORS /E.G. FREQUENT FLYER STATUS/MILITARY/",
"CREDIT CARD FORM OF PAYMENT/EARLY PURCHASE OVER INTERNET,ETC./"
]
}
},
"BaseFare" : {
"Amount" : "34.00",
"CurrencyCode" : "EUR"
},
"Construction" : {
"Amount" : "39.95",
"CurrencyCode" : "NUC",
"RateOfExchange" : "0.850860"
},
"Taxes" : {
"TotalAmount" : "91.30",
"Tax" : [
{
"Amount" : "26.00",
"TaxCode" : "YQI",
"TaxName" : "SERVICE FEE - CARRIER-IMPOSED",
"TicketingTaxCode" : "YQ"
},
{
"Amount" : "16.33",
"TaxCode" : "FR",
"TaxName" : "CIVIL AVIATION TAX DOMESTIC AN",
"TicketingTaxCode" : "FR"
},
{
"Amount" : "13.09",
"TaxCode" : "QX",
"TaxName" : "PASSENGER SERVICE CHARGE INTER",
"TicketingTaxCode" : "QX"
},
{
"Amount" : "1.13",
"TaxCode" : "IZ",
"TaxName" : "AIR PASSENGER SOLIDARITY TAX",
"TicketingTaxCode" : "IZ"
},
{
"Amount" : "14.51",
"TaxCode" : "GB",
"TaxName" : "AIR PASSENGER DUTY APD",
"TicketingTaxCode" : "GB"
},
{
"Amount" : "18.74",
"TaxCode" : "UB",
"TaxName" : "PASSENGER SERVICE CHARGE DEPAR",
"TicketingTaxCode" : "UB"
},
{
"Amount" : "1.50",
"TaxCode" : "O4",
"TaxName" : "AIR PASSENGER SOLIDARITY TAX S",
"TicketingTaxCode" : "O4"
}
]
},
"TotalFare" : {
"Amount" : "125.30",
"CurrencyCode" : "EUR"
}
},
"PassengerTypeQuantity" : {
"Code" : "ADT",
"Quantity" : "1"
},
"PTC_FareBreakdown" : [
{
"Cabin" : "Y",
"FareBasis" : {
"Code" : "GS50OALG",
"FareAmount" : "17.62",
"FarePassengerType" : "ADT",
"FareType" : "P",
"FilingCarrier" : "AF",
"GlobalInd" : "EH",
"Market" : "PARLON"
},
"FreeBaggageAllowance" : "NONIL"
},
{
"Cabin" : "Y",
"FareBasis" : {
"Code" : "XS50OALG",
"FareAmount" : "22.33",
"FarePassengerType" : "ADT",
"FareType" : "P",
"FilingCarrier" : "AF",
"GlobalInd" : "EH",
"Market" : "PARLON"
},
"FreeBaggageAllowance" : "NONIL"
}
]
}
]
}
}
}
],
"TravelItineraryRead" : {
"TravelItinerary" : {
"CustomerInfo" : {
...
},
"ItineraryInfo" : {
"ItineraryPricing" : {
"PriceQuote" : [
{
"RPH" : "1",
"MiscInformation" : {
"SignatureLine" : [
{
"ExpirationDateTime" : "00:00",
"Source" : "SYS",
"Status" : "ACTIVE",
"Text" : "N1GJ N1GJ*AWS 1329/19NOV20"
}
]
},
"PricedItinerary" : [
{
"DisplayOnly" : false,
"InputMessage" : "WPFCK¥S1*ZZGS50OALG¥S2*ZZXS50OALG¥P1ADT¥RQ",
"RPH" : "1",
"StatusCode" : "A",
"TaxExempt" : false,
"ValidatingCarrier" : "AF",
"StoredDateTime" : "2020-11-19T13:29",
"AirItineraryPricingInfo" : {
"ItinTotalFare" : [
{
"BaseFare" : {
"Amount" : "34.00",
"CurrencyCode" : "EUR"
},
"Taxes" : {
"Tax" : {
"Amount" : "91.30",
"TaxCode" : "XT"
},
"TaxBreakdownCode" : [
{
"TaxPaid" : false,
"content" : "26.00YQ"
},
{
"TaxPaid" : false,
"content" : "16.33FR"
},
{
"TaxPaid" : false,
"content" : "13.09QX"
},
{
"TaxPaid" : false,
"content" : "1.13IZ"
},
{
"TaxPaid" : false,
"content" : "14.51GB"
},
{
"TaxPaid" : false,
"content" : "18.74UB"
},
{
"TaxPaid" : false,
"content" : "1.50O4"
}
]
},
"TotalFare" : {
"Amount" : "125.30",
"CurrencyCode" : "EUR"
},
"Totals" : {
"BaseFare" : {
"Amount" : "34.00"
},
"Taxes" : {
"Tax" : {
"Amount" : "91.30"
}
},
"TotalFare" : {
"Amount" : "125.30"
}
}
}
],
"PassengerTypeQuantity" : [
{
"Code" : "ADT",
"Quantity" : "01"
}
],
"PTC_FareBreakdown" : [
{
"Endorsements" : {
"Endorsement" : [
{
"type" : "PRICING_PARAMETER",
"Text" : "WPFCK$S1*ZZGS50OALG$S2*ZZXS50OALG$P1ADT$RQ"
},
{
"type" : "WARNING",
"Text" : "VALIDATING CARRIER - AF"
},
{
"type" : "WARNING",
"Text" : "CAT 15 SALES RESTRICTIONS FREE TEXT FOUND - VERIFY RULES"
}
]
},
"FareBasis" : [
{
"Code" : "GS50OALG/XS50OALG"
}
],
"FareCalculation" : {
"Text" : [
"PAR AF LON17.62AF PAR22.33NUC39.95END ROE0.85086"
]
},
"FareSource" : "ATPC",
"FlightSegment" : [
{
"ConnectionInd" : "O",
"DepartureDateTime" : "02-17T13:15",
"FlightNumber" : "1780",
"ResBookDesigCode" : "G",
"SegmentNumber" : "1",
"Status" : "OK",
"BaggageAllowance" : {
"Number" : "NIL"
},
"FareBasis" : {
"Code" : "GS50OALG"
},
"MarketingAirline" : {
"Code" : "AF",
"FlightNumber" : "1780"
},
"OriginLocation" : {
"LocationCode" : "CDG"
},
"ValidityDates" : {
"NotValidAfter" : "2021-02-17",
"NotValidBefore" : "2021-02-17"
}
},
{
"ConnectionInd" : "O",
"DepartureDateTime" : "02-26T11:30",
"FlightNumber" : "1581",
"ResBookDesigCode" : "X",
"SegmentNumber" : "2",
"Status" : "OK",
"BaggageAllowance" : {
"Number" : "NIL"
},
"FareBasis" : {
"Code" : "XS50OALG"
},
"MarketingAirline" : {
"Code" : "AF",
"FlightNumber" : "1581"
},
"OriginLocation" : {
"LocationCode" : "LHR"
},
"ValidityDates" : {
"NotValidAfter" : "2021-02-26",
"NotValidBefore" : "2021-02-26"
}
},
{
"OriginLocation" : {
"LocationCode" : "CDG"
}
}
],
"FareComponent" : [
{
"FareBasisCode" : "GS50OALG",
"FareDirectionality" : "FROM",
"Amount" : "1762",
"TicketDesignator" : "",
"GoverningCarrier" : "AF",
"FareComponentNumber" : "1",
"Location" : {
"Origin" : "PAR",
"Destination" : "LON"
},
"Dates" : {
"DepartureDateTime" : "02-17T13:15",
"ArrivalDateTime" : "02-17T13:45"
},
"FlightSegmentNumbers" : {
"FlightSegmentNumber" : [
"1"
]
}
},
{
"FareBasisCode" : "XS50OALG",
"FareDirectionality" : "TO",
"Amount" : "2233",
"TicketDesignator" : "",
"GoverningCarrier" : "AF",
"FareComponentNumber" : "2",
"Location" : {
"Origin" : "LON",
"Destination" : "PAR"
},
"Dates" : {
"DepartureDateTime" : "02-26T11:30",
"ArrivalDateTime" : "02-26T13:50"
},
"FlightSegmentNumbers" : {
"FlightSegmentNumber" : [
"2"
]
}
}
]
}
]
}
}
],
"ResponseHeader" : {
"Text" : [
"FARE - PRICE RETAINED",
"FARE USED TO CALCULATE DISCOUNT",
"FARE NOT GUARANTEED UNTIL TICKETED"
]
},
"PriceQuotePlus" : {
"DomesticIntlInd" : "I",
"PricingStatus" : "S",
"VerifyFareCalc" : false,
"ItineraryChanged" : false,
"ManualFare" : false,
"NegotiatedFare" : false,
"SystemIndicator" : "S",
"NUCSuppresion" : false,
"SubjToGovtApproval" : false,
"IT_BT_Fare" : "BT",
"DisplayOnly" : false,
"DiscountAmount" : "0",
"PassengerInfo" : {
"PassengerType" : "ADT",
"PassengerData" : [
{
"NameNumber" : "01.01",
"content" : "TEST/TEST"
}
]
},
"TicketingInstructionsInfo" : {}
}
}
],
"PriceQuoteTotals" : {
"BaseFare" : {
"Amount" : "34.00"
},
"Taxes" : {
"Tax" : {
"Amount" : "91.30"
}
},
"TotalFare" : {
"Amount" : "125.30"
}
}
},
"Ticketing" : [
{
"RPH" : "01",
"TicketTimeLimit" : "TAWL4GJ19NOV009/"
}
]
},
"ItineraryRef" : {
...
},
"SpecialServiceInfo" : [
{
"RPH" : "001",
"Type" : "GFX",
"Id" : "14",
"Service" : {
"SSR_Code" : "SSR",
"SSR_Type" : "DOCS",
"Airline" : {
"Code" : "AF"
},
"PersonName" : [
{
"NameNumber" : "01.01",
"content" : "TEST/TEST"
}
],
"Text" : [
"HK1/DB/13JAN1991/M/TEST/TEST"
]
}
},
{
"RPH" : "002",
"Type" : "GFX",
"Id" : "15",
"Service" : {
"SSR_Code" : "SSR",
"SSR_Type" : "CTCM",
"Airline" : {
"Code" : "AF"
},
"PersonName" : [
{
"NameNumber" : "01.01",
"content" : "TEST/TEST"
}
],
"Text" : [
"HK1/0033142890939"
]
}
},
{
"RPH" : "003",
"Type" : "GFX",
"Id" : "16",
"Service" : {
"SSR_Code" : "SSR",
"SSR_Type" : "CTCE",
"Airline" : {
"Code" : "AF"
},
"PersonName" : [
{
"NameNumber" : "01.01",
"content" : "TEST/TEST"
}
],
"Text" : [
"TEST"
]
}
}
]
}
}
}
Do I need to specify something in CreatePassengerNameRecordRQ to freeze the fare quote ?
Is there any other action needed to access this special option offered by some airlines ?
Thank you !

mapper_parsing_exception in Elasticsearch(Reason: No type specified for field [X])

I wanted to provide explicit mapping to the fields in my document, So I defined a mapping for my index demo and It looks like this below:
PUT /demo
{
"mappings": {
"properties": {
"X" : {
"X" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"Sub_X" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
After running the query , I am getting error as :
{
"error" : {
"root_cause" : [
{
"type" : "mapper_parsing_exception",
"reason" : "No type specified for field [X]"
}
],
"type" : "mapper_parsing_exception",
"reason" : "Failed to parse mapping [_doc]: No type specified for field [X]",
"caused_by" : {
"type" : "mapper_parsing_exception",
"reason" : "No type specified for field [X]"
}
},
"status" : 400
}
The field X in json document looks like :
"X" : {
"X" : [
"a"
],
"Sub_X" : [
[
"b"
]
]
},
Please help me out with this elastic search mapper_parse_exception error.
What you have is called nested data type
You have X which in turn contains X and Sub_X.
Mapping:
{
"properties": {
"X": {
"type": "nested"
}
}
}
Data:
{
"X": {
"X": [
"a"
],
"Sub_X": [
[
"b"
]
]
}
}
Query:
{
"query": {
"nested": {
"path": "X",
"query": {
"bool": {
"must": [
{ "match": { "X.X": "a" }},
{ "match": { "X.Sub_X": "b" }}
]
}
}
}
}
}
It outputs the document.

how to add data to the repeatable fields in avro schema?

I'm trying to test avro serde and deserde without code generation (I completed this task using code generation). Schema is as follows
{
"type": "record",
"name" : "person",
"namespace" : "avro",
"fields": [
{ "name" : "personname", "type": ["null","string"] },
{ "name" : "personId", "type": ["null","string"] },
{ "name" : "Addresses", "type": {
"type": "array",
"items": [ {
"type" : "record",
"name" : "Address",
"fields" : [
{ "name" : "addressLine1", "type": ["null", "string"] },
{ "name" : "addressLine2", "type": ["null", "string"] },
{ "name" : "city", "type": ["null", "string"] },
{ "name" : "state", "type": ["null", "string"] },
{ "name" : "zipcode", "type": ["null", "string"] }
]
}]
}
},
{ "name" : "contact", "type" : ["null", "string"]}
]
}
I understand this is how data is added to the schema.
Schema schema = new Schema.Parser().parse(new File("src/person.avsc.txt"));
GenericRecord person1 = new GenericData.Record(schema);
person1.put("personname", "goud");
But how do I add city, state etc to address and then add it to addresses?
GenericRecord address1 = new GenericData.Record(schema);
address1.put("city", "SanJose");
The above snippet doesn't work. I tried to look into GenericArray, but I couldn't get my head around it.
You need to describe inner complex type ("type" : "record", "name" : "Address") in separate schema, like this:
{
"type" : "record",
"name" : "Address",
"fields" : [
{ "name" : "addressLine1", "type": ["null", "string"] },
{ "name" : "addressLine2", "type": ["null", "string"] },
{ "name" : "city", "type": ["null", "string"] },
{ "name" : "state", "type": ["null", "string"] },
{ "name" : "zipcode", "type": ["null", "string"] }
]
}
Then you may create an inner object:
Schema innerSchema = new Schema.Parser().parse(new File("person_address.avsc"));
GenericRecord address = new GenericData.Record(innerSchema);
address.put("addressLine1", "adr_1");
address.put("addressLine2", "adr_2");
address.put("city", "test_city");
address.put("state", "test_state");
address.put("zipcode", "zipcode_00000");
Then add an inner object you created to ArrayList.
At last, create the main object and add all this staff in it.
Here is full example in java:
Schema innerSchema = new Schema.Parser().parse(new File("person_address.avsc"));
GenericRecord address = new GenericData.Record(innerSchema);
address.put("addressLine1", "adr_1");
address.put("addressLine2", "adr_2");
address.put("city", "test_city");
address.put("state", "test_state");
address.put("zipcode", "zipcode_00000");
ArrayList<GenericRecord> addresses = new ArrayList<>();
addresses.add(address);
Schema mainSchema = new Schema.Parser().parse(new File("person.avsc"));
GenericRecord person1 = new GenericData.Record(mainSchema);
person1.put("personname", "goud");
person1.put("personId", "123_id");
person1.put("Addresses", addresses);
Result:
{
"personname": "goud",
"personId": "123_id",
"Addresses": [
{
"addressLine1": "adr_1",
"addressLine2": "adr_2",
"city": "test_city",
"state": "test_state",
"zipcode": "zipcode_00000"
}
],
"contact": "test_contact"
}

Query for missing fields in nested documents

I have a user document which contains many tags
Here is the mapping:
{
"user" : {
"properties" : {
"tags" : {
"type" : "nested",
"properties" : {
"id" : {
"type" : "string",
"index" : "not_analyzed",
"store" : "yes"
},
"current" : {
"type" : "boolean"
},
"type" : {
"type" : "string"
},
"value" : {
"type" : "multi_field",
"fields" : {
"value" : {
"type" : "string",
"analyzer" : "name_analyzer"
},
"value_untouched" : {
"type" : "string",
"index" : "not_analyzed",
"include_in_all" : false
}
}
}
}
}
}
}
}
Here are the sample user documents:
User 1
{
"created_at": 1317484762000,
"updated_at": 1367040856000,
"tags": [
{
"type": "college",
"value": "Dhirubhai Ambani Institute of Information and Communication Technology",
"id": "a6f51ef8b34eb8f24d1c5be5e4ff509e2a361829"
},
{
"type": "company",
"value": "alma connect",
"id": "58ad4afcc8415216ea451339aaecf311ed40e132"
},
{
"type": "company",
"value": "Google",
"id": "93bc8199c5fe7adfd181d59e7182c73fec74eab5",
"current": true
},
{
"type": "discipline",
"value": "B.Tech.",
"id": "a7706af7f1477cbb1ac0ceb0e8531de8da4ef1eb",
"institute_id": "4fb424a5addf32296f00013a"
},
]
}
User 2:
{
"created_at": 1318513355000,
"updated_at": 1364888695000,
"tags": [
{
"type": "college",
"value": "Dhirubhai Ambani Institute of Information and Communication Technology",
"id": "a6f51ef8b34eb8f24d1c5be5e4ff509e2a361829"
},
{
"type": "college",
"value": "Bharatiya Vidya Bhavan's Public School, Jubilee hills, Hyderabad",
"id": "d20730345465a974dc61f2132eb72b04e2f5330c"
},
{
"type": "company",
"value": "Alma Connect",
"id": "93bc8199c5fe7adfd181d59e7182c73fec74eab5"
},
{
"type": "sector",
"value": "Website and Software Development",
"id": "dc387d78fc99ab43e6ae2b83562c85cf3503a8a4"
}
]
}
User 3:
{
"created_at": 1318513355001,
"updated_at": 1364888695010,
"tags": [
{
"type": "college",
"value": "Dhirubhai Ambani Institute of Information and Communication Technology",
"id": "a6f51ef8b34eb8f24d1c5be5e4ff509e2a361821"
},
{
"type": "sector",
"value": "Website and Software Development",
"id": "dc387d78fc99ab43e6ae2b83562c85cf3503a8a1"
}
]
}
Using the above ES documents for search, I want to construct a query where I need to fetch users who have company tags in nested tag documents or the users who do not have any company tags. What will be my search query?
For example in above case, if search for google tag, then the returned documents should be 'user 1' and 'user 3' (as user 1 has company tag google and user 3 has no company tag). User 2 is not returned as it has a company tag other than google too.
Not trivial at all, mainly due to the not have a type:company tag clause. Here's what I came up with:
{
"or" : {
"filters" : [ {
"nested" : {
"filter" : {
"and" : {
"filters" : [ {
"term" : {
"tags.value" : "google"
}
}, {
"term" : {
"tags.type" : "company"
}
} ]
}
},
"path" : "tags"
}
}, {
"not" : {
"filter" : {
"nested" : {
"filter" : {
"term" : {
"tags.type" : "company"
}
},
"path" : "tags"
}
}
}
} ]
}
}
It contains an or filter with two nested clauses: the first one finds the documents that have tags.type:company and tags.value:google, while the second one finds all the documents that don't have any tags.type:company.
This needs to be optimized though since and/or/not filters don't take advantage of caching for filters that work with bitsets, like the term filter does. It would be best to take some more time to find a way to use a bool filter and obtain the same result. Have a lookt this article to know more.