Created
November 2, 2023 16:59
-
-
Save Muffinman/24aa0884f72340aaf4c6ef982325dbe1 to your computer and use it in GitHub Desktop.
Typesense query token problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export TYPESENSE_API_KEY=xyz | |
curl "http://localhost:8108/debug" \ | |
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" | |
curl "http://localhost:8108/collections" \ | |
-X POST \ | |
-H "Content-Type: application/json" \ | |
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \ | |
-d '{"name":"products","enable_nested_fields":true,"fields":[{"name":"id","type":"string","sort":true},{"name":"_id","type":"int64"},{"name":"published","type":"bool"},{"name":"collection","type":"bool","facet":true},{"name":"num_collections","type":"int64","sort":true},{"name":"code","type":"string"},{"name":"title","type":"string"},{"name":"title_sortable","type":"string","sort":true},{"name":"content","type":"string","optional":true},{"name":"facet_.*","type":"string","facet":true,"optional":true},{"name":"features","type":"object[]","optional":true},{"name":"sortable_price","type":"float","sort":true},{"name":"sortable_stock","type":"float","sort":true},{"name":"altcode","type":"string","optional":true},{"name":"subcodes","type":"string[]","optional":true},{"name":"oldcodes","type":"string[]","optional":true},{"name":"barcode","type":"string","optional":true},{"name":"categories","type":"int64[]","facet":true},{"name":"categories_lft","type":"int64[]","facet":true},{"name":"categories_rgt","type":"int64[]","facet":true},{"name":"category_names","type":"string[]","optional":true},{"name":"keywords","type":"string[]","optional":true},{"name":"instance_title_sortable","type":"object[]","optional":true},{"name":"oem_numbers","type":"string[]","optional":true},{"name":"category_sortable","type":"object[]","optional":true},{"name":"machine_models","type":"int64[]","optional":true},{"name":"created_at","type":"int64"}],"default_sorting_field":"title_sortable"}' | |
curl "http://localhost:8108/collections/products/documents/import?action=create" \ | |
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \ | |
-H "Content-Type: text/plain" \ | |
-X POST \ | |
-d '{"id":"107534","_id":107534,"published":true,"collection":false,"num_collections":0,"code":"HEL2871","title":"JCB Style Round Body Fuel Pump Top Style OEM; 17\/932200","title_sortable":"jcb-style-round-body-fuel-pump-top-style-oem-17932200","content":"","sortable_price":88.6,"sortable_stock":2,"altcode":"","subcodes":[],"oldcodes":[],"barcode":null,"categories":[92,2135,2242,2386,2399],"categories_lft":[1388,916,1309,1204,1158],"categories_rgt":[1389,917,1310,1205,1159],"category_names":["Plant > Plant Electrics > Automotive > Fuel Pumps","Plant > Telehandler Parts > JCB Style Telehandler Parts > JCB Style Telehandler Fuel Pumps","Plant > JCB > JCB Style Fuel Pumps","Plant > JCB > Telehandler > JCB Style Telehandler Fuel Products","Plant > JCB > Excavator > JCB Style Excavator Fuel Products"],"keywords":["fuel pump","pump","fuel","17\/932200"],"instance_title_sortable":[{"category_id":2135,"title":"jcb-style-round-body-fuel-pump-top-style-oem17932200"}],"category_sortable":[{"category_id":92,"rank":8},{"category_id":2135,"rank":9999},{"category_id":2242,"rank":9999},{"category_id":2386,"rank":9999},{"category_id":2399,"rank":9999}],"machine_models":[3117],"created_at":1572887513,"features":[{"id":71,"name":"OEM Number","value":"17\/932200"}],"facet_71":"17\/932200","oem_numbers":["17\/932200"]} | |
{"id":"6068","_id":6068,"published":true,"collection":false,"num_collections":0,"code":"HEL0302","title":"Round Body Fuel Pump With Plug 12 Volt","title_sortable":"round-body-fuel-pump-with-plug-12-volt","content":"","sortable_price":37,"sortable_stock":238,"altcode":"","subcodes":[],"oldcodes":[],"barcode":"5055994471881","categories":[92,2386,2392,2399],"categories_lft":[1388,1204,1296,1158],"categories_rgt":[1389,1205,1297,1159],"category_names":["Plant > Plant Electrics > Automotive > Fuel Pumps","Plant > JCB > Telehandler > JCB Style Telehandler Fuel Products","Plant > JCB > 3Cx Backhoe Loader > JCB Style 3Cx Backhoe Loader Fuel Products","Plant > JCB > Excavator > JCB Style Excavator Fuel Products"],"keywords":["round body","fuel pump","12 volt"],"instance_title_sortable":[],"category_sortable":[{"category_id":92,"rank":6},{"category_id":2386,"rank":9999},{"category_id":2392,"rank":9999},{"category_id":2399,"rank":9999}],"machine_models":[3117,3122,3139],"created_at":1484733216,"features":[{"id":71,"name":"OEM Number","value":"02\/634780"}],"facet_71":"02\/634780","oem_numbers":["02\/634780"]} | |
{"id":"6142","_id":6142,"published":true,"collection":false,"num_collections":1,"code":"HEL0400","title":"Arctic Cable 3 Core - Artic Cable Yellow 4mm 100Mtr","title_sortable":"arctic-cable-3-core-artic-cable-yellow-4mm-100mtr","content":"","sortable_price":251.81,"sortable_stock":1,"altcode":"","subcodes":[],"oldcodes":["HEL 400"],"barcode":"5055994418121","categories":[],"categories_lft":[],"categories_rgt":[],"category_names":[],"keywords":["artic","cable","yellow","4mm","100mtr"],"instance_title_sortable":[],"category_sortable":[],"machine_models":[],"created_at":1484733219,"facet_55":"4.0mm","facet_39":"Yellow"} | |
{"id":"15287","_id":15287,"published":true,"collection":false,"num_collections":0,"code":"HTL0400","title":"Round Brake Pad Pair Long Life Woven OEM; T51443, 15\/920103","title_sortable":"round-brake-pad-pair-long-life-woven-oem-t51443-15920103","content":"","sortable_price":39.12,"sortable_stock":81,"altcode":"","subcodes":[],"oldcodes":["HTL 400"],"barcode":"5055994476473","categories":[324,1204,1389,2097,2134,2149,2158,2214,2216,2217],"categories_lft":[987,839,651,758,914,826,806,1212,1234,1270],"categories_rgt":[988,840,652,759,915,827,807,1213,1235,1271],"category_names":["Plant > Plant Accessories > Brake Pads","Plant > Dumper Spares > Dumper Brake Callipers & Pads","Plant > Excavator > JCB Style Excavator Spares","Plant > Dumper Spares > Mecalac Terex Benford > Mecalac Terex Brakes & Throttle","Plant > Telehandler Parts > JCB Style Telehandler Parts > JCB Style Telehandler Parts & Accessories","Plant > Dumper Spares > Wacker Neuson > Wacker Neuson Dumper Brakes & Throttle","Plant > Dumper Spares > JCB Style Dumper Spares > JCB Style Dumper Brakes & Throttle","Plant > JCB > Telehandler > JCB Style Telehandler Brakes & Transmission","Plant > JCB > Wheeled Loader > JCB Style Wheeled Loader Brakes & Transmission","Plant > JCB > 3Cx Backhoe Loader > JCB Style 3Cx Backhoe Loader Brakes & Transmission"],"keywords":["round","brake","pad","htl0400","1594-1151p","1586-1404a","terex","benford","wacker","neuson","jcb","barford"],"instance_title_sortable":[{"category_id":1204,"title":"benford-barford-jcb-style-neuson-terex-thwaites-brake-pad-round-pair-hard-wearing"},{"category_id":1389,"title":"jcb-style-brake-pad-round-pair-harder-wearing"},{"category_id":2097,"title":"benford-terex-mecalac-brake-pad-round-pair-long-life-oem-1594-1151p-1586-1404a"},{"category_id":2134,"title":"benford-barford-jcb-style-neuson-terex-thwaites-brake-pad-round-pair-hard-wearing"},{"category_id":2214,"title":"jcb-style-brake-pad-round-pair-hard-wearing-oem-47800849"},{"category_id":2216,"title":"jcb-style-brake-pad-round-pair-hard-wearing-oem-47800849"},{"category_id":2217,"title":"jcb-style-brake-pad-round-pair-hard-wearing-oem-47800849"}],"category_sortable":[{"category_id":324,"rank":1},{"category_id":1204,"rank":9999},{"category_id":1389,"rank":9999},{"category_id":2097,"rank":9999},{"category_id":2134,"rank":9999},{"category_id":2149,"rank":9999},{"category_id":2158,"rank":9999},{"category_id":2214,"rank":9999},{"category_id":2216,"rank":9999},{"category_id":2217,"rank":9999}],"machine_models":[3127,3130,3137,3141],"created_at":1484733657,"features":[{"id":71,"name":"OEM Number","value":"15\/920103, 478\/00849, 1594-1151P, 1586-1404A, T51443, 1000078847"}],"facet_71":"15\/920103, 478\/00849, 1594-1151P, 1586-1404A, T51443, 1000078847","oem_numbers":["15\/920103","478\/00849","1594-1151P","1586-1404A","T51443","1000078847"]} | |
{"id":"15011","_id":15011,"published":true,"collection":false,"num_collections":0,"code":"HTL0019","title":"Round Brake Pad Pair Standard OEM;15\/920103, 478\/00849","title_sortable":"round-brake-pad-pair-standard-oem15920103-47800849","content":"","sortable_price":21.42,"sortable_stock":34,"altcode":"","subcodes":[],"oldcodes":[],"barcode":"5055994490769","categories":[324,1204,1389,2097,2134,2149,2158,2214,2216,2217],"categories_lft":[987,839,651,758,914,826,806,1212,1234,1270],"categories_rgt":[988,840,652,759,915,827,807,1213,1235,1271],"category_names":["Plant > Plant Accessories > Brake Pads","Plant > Dumper Spares > Dumper Brake Callipers & Pads","Plant > Excavator > JCB Style Excavator Spares","Plant > Dumper Spares > Mecalac Terex Benford > Mecalac Terex Brakes & Throttle","Plant > Telehandler Parts > JCB Style Telehandler Parts > JCB Style Telehandler Parts & Accessories","Plant > Dumper Spares > Wacker Neuson > Wacker Neuson Dumper Brakes & Throttle","Plant > Dumper Spares > JCB Style Dumper Spares > JCB Style Dumper Brakes & Throttle","Plant > JCB > Telehandler > JCB Style Telehandler Brakes & Transmission","Plant > JCB > Wheeled Loader > JCB Style Wheeled Loader Brakes & Transmission","Plant > JCB > 3Cx Backhoe Loader > JCB Style 3Cx Backhoe Loader Brakes & Transmission"],"keywords":["benford","barford","jcb","neuson","terex","thwaites","brake","pad","round","pair","budget","htl0019","1594-1151p","1596-1404a"],"instance_title_sortable":[{"category_id":1204,"title":"benford-barford-jcb-style-neuson-terex-thwaites-brake-pad-round-pair-budget-oem-1594-1151p-1586-1404a-15920103-47800849"},{"category_id":1389,"title":"jcb-style-brake-pad-round-pair-budget-oem-15920103-47800849"},{"category_id":2097,"title":"benford-terex-mecalac-brake-pad-round-pair-budget-oem-1594-1151p-1586-1404a"},{"category_id":2134,"title":"jcb-style-brake-pad-round-pair-budget-oem-15920103-47800849"},{"category_id":2214,"title":"jcb-style-brake-pad-round-pair-budget-oem15920103-47800849"},{"category_id":2216,"title":"jcb-style-brake-pad-round-pair-budget-oem15920103-47800849"},{"category_id":2217,"title":"jcb-style-brake-pad-round-pair-budget-oem15920103-47800849"}],"category_sortable":[{"category_id":324,"rank":0},{"category_id":1204,"rank":9999},{"category_id":1389,"rank":9999},{"category_id":2097,"rank":9999},{"category_id":2134,"rank":9999},{"category_id":2149,"rank":9999},{"category_id":2158,"rank":9999},{"category_id":2214,"rank":9999},{"category_id":2216,"rank":9999},{"category_id":2217,"rank":9999},{"category_id":2445,"rank":9999}],"machine_models":[3127,3130,3137,3141],"created_at":1484733642,"features":[{"id":71,"name":"OEM Number","value":"478\/00849"}],"facet_71":"478\/00849","oem_numbers":["478\/00849"]} | |
{"id":"6674","_id":6674,"published":true,"collection":false,"num_collections":2,"code":"HEL1324","title":"Round Reflectors - JCB Style Round Reflector - White - Bolt On OEM; 700\/50207","title_sortable":"round-reflectors-jcb-style-round-reflector-white-bolt-on-oem-70050207","content":"","sortable_price":1.3900000000000001,"sortable_stock":28,"altcode":"","subcodes":[],"oldcodes":["HEL 322W","HMP1483"],"barcode":"5055994423330","categories":[2401],"categories_lft":[1166],"categories_rgt":[1167],"category_names":["Plant > JCB > Excavator > JCB Style Excavator Lighting"],"keywords":["round","reflector","white","bolt on","700\/50207","JCB","HEL1324"],"instance_title_sortable":[],"category_sortable":[{"category_id":2401,"rank":9999}],"machine_models":[3117],"created_at":1484733240,"facet_39":"White","features":[{"id":71,"name":"OEM Number","value":"700\/50207, T101990"}],"facet_71":"700\/50207, T101990","facet_4":"Bolt On","oem_numbers":["700\/50207","T101990","T101990"]} | |
{"id":"124312","_id":124312,"published":true,"collection":false,"num_collections":0,"code":"HMP3576","title":"JCB Style Air Vent OEM: 141\/00494","title_sortable":"jcb-style-air-vent-oem-14100494","content":"","sortable_price":28.24,"sortable_stock":5,"altcode":"141\/00494","subcodes":[],"oldcodes":[],"barcode":null,"categories":[2280,2283],"categories_lft":[1186,1240],"categories_rgt":[1187,1241],"category_names":["Plant > JCB > Telehandler > JCB Style Telehandler Interior And Trim Parts","Plant > JCB > Wheeled Loader > JCB Style Wheeled Loader Interior And Trim Parts"],"keywords":["JCB","JCB air vent","air vent","vent","141\/00494","141-00494"],"instance_title_sortable":[],"category_sortable":[{"category_id":2280,"rank":9999},{"category_id":2283,"rank":9999}],"machine_models":[],"created_at":1655379306,"features":[{"id":71,"name":"OEM Number","value":"141\/00494"}],"facet_71":"141\/00494","oem_numbers":["141\/00494"]} | |
{"id":"113889","_id":113889,"published":true,"collection":false,"num_collections":0,"code":"HTL2600","title":"JCB Style Air Vent OEM; 331\/25505","title_sortable":"jcb-style-air-vent-oem-33125505","content":"","sortable_price":7.08,"sortable_stock":37,"altcode":"","subcodes":[],"oldcodes":[],"barcode":null,"categories":[2272,2276],"categories_lft":[1278,1152],"categories_rgt":[1279,1153],"category_names":["Plant > JCB > 3Cx Backhoe Loader > JCB Style 3Cx Backhoe Loader Interior And Trim Parts","Plant > JCB > Excavator > JCB Style Excavator Interior And Trim Parts"],"keywords":["jcb","air","vent","air vent","331\/25505"],"instance_title_sortable":[],"category_sortable":[{"category_id":2272,"rank":9999},{"category_id":2276,"rank":9999}],"machine_models":[],"created_at":1614941356,"features":[{"id":71,"name":"OEM Number","value":"331\/25505"}],"facet_71":"331\/25505","oem_numbers":["331\/25505"]} | |
{"id":"113106","_id":113106,"published":true,"collection":false,"num_collections":0,"code":"HTL2164","title":"JCB Style Air Vent OEM; 331\/26974","title_sortable":"jcb-style-air-vent-oem-33126974","content":"","sortable_price":12,"sortable_stock":175,"altcode":"","subcodes":[],"oldcodes":[],"barcode":"5055994446421","categories":[1389,2134,2272,2276,2280,2283],"categories_lft":[651,914,1278,1152,1186,1240],"categories_rgt":[652,915,1279,1153,1187,1241],"category_names":["Plant > Excavator > JCB Style Excavator Spares","Plant > Telehandler Parts > JCB Style Telehandler Parts > JCB Style Telehandler Parts & Accessories","Plant > JCB > 3Cx Backhoe Loader > JCB Style 3Cx Backhoe Loader Interior And Trim Parts","Plant > JCB > Excavator > JCB Style Excavator Interior And Trim Parts","Plant > JCB > Telehandler > JCB Style Telehandler Interior And Trim Parts","Plant > JCB > Wheeled Loader > JCB Style Wheeled Loader Interior And Trim Parts"],"keywords":["331\/26974","JCB","air","vent","telehandler"],"instance_title_sortable":[],"category_sortable":[{"category_id":1389,"rank":9999},{"category_id":2134,"rank":9999},{"category_id":2231,"rank":9999},{"category_id":2232,"rank":9999},{"category_id":2272,"rank":9999},{"category_id":2276,"rank":9999},{"category_id":2280,"rank":9999},{"category_id":2283,"rank":9999}],"machine_models":[3121,3125,3171,3136,3140],"created_at":1606322936,"features":[{"id":71,"name":"OEM Number","value":"331\/26974"}],"facet_71":"331\/26974","oem_numbers":["331\/26974"]} | |
{"id":"113888","_id":113888,"published":true,"collection":false,"num_collections":0,"code":"HTL2599","title":"JCB Style Air Vent OEM: 331\/31000","title_sortable":"jcb-style-air-vent-oem-33131000","content":"","sortable_price":8.1,"sortable_stock":21,"altcode":"","subcodes":[],"oldcodes":[],"barcode":null,"categories":[2211,2272,2276],"categories_lft":[1226,1278,1152],"categories_rgt":[1227,1279,1153],"category_names":["Plant > JCB > Roller > Roller Accessories","Plant > JCB > 3Cx Backhoe Loader > JCB Style 3Cx Backhoe Loader Interior And Trim Parts","Plant > JCB > Excavator > JCB Style Excavator Interior And Trim Parts"],"keywords":["jcb","air","vent","331\/31000"],"instance_title_sortable":[],"category_sortable":[{"category_id":2211,"rank":9999},{"category_id":2272,"rank":9999},{"category_id":2276,"rank":9999}],"machine_models":[],"created_at":1614941356,"features":[{"id":71,"name":"OEM Number","value":"331\/31000"}],"facet_71":"331\/31000","oem_numbers":["331\/31000"]} | |
{"id":"123280","_id":123280,"published":true,"collection":false,"num_collections":0,"code":"HMP2775","title":"JCB Style Oblong JCB Air Vent OEM: 210\/32607","title_sortable":"jcb-style-oblong-jcb-air-vent-oem-21032607","content":"","sortable_price":18.99,"sortable_stock":7,"altcode":"210\/32607","subcodes":[],"oldcodes":[],"barcode":"5055994407736","categories":[2276,2280,2283],"categories_lft":[1152,1186,1240],"categories_rgt":[1153,1187,1241],"category_names":["Plant > JCB > Excavator > JCB Style Excavator Interior And Trim Parts","Plant > JCB > Telehandler > JCB Style Telehandler Interior And Trim Parts","Plant > JCB > Wheeled Loader > JCB Style Wheeled Loader Interior And Trim Parts"],"keywords":["JCB","JCB Air Vent","Loadall oblong air vent","210\/32607","210-32607"],"instance_title_sortable":[],"category_sortable":[{"category_id":2276,"rank":9999},{"category_id":2280,"rank":9999},{"category_id":2283,"rank":9999}],"machine_models":[],"created_at":1645446903,"features":[{"id":71,"name":"OEM Number","value":"210\/32607"}],"facet_71":"210\/32607","oem_numbers":["210\/32607"]}' | |
# First query | |
curl "http://localhost:8108/collections/products/documents/search?query_by=code,altcode,title,subcodes,oldcodes,barcode,category_names,keywords,oem_numbers,content&query_by_weights=10,10,1,1,1,1,1,1,1,1&filter_by=published:=true+&&+sortable_stock:>=0&sort_by=title_sortable:asc&page=1&per_page=5&text_match_type=max_weight&q=JCB+Air+Vent+round" \ | |
-X GET \ | |
-H "Content-Type: application/json" \ | |
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" | |
# Second query, totally different results from just reordering the query string tokens | |
curl "http://localhost:8108/collections/products/documents/search?query_by=code,altcode,title,subcodes,oldcodes,barcode,category_names,keywords,oem_numbers,content&query_by_weights=10,10,1,1,1,1,1,1,1,1&filter_by=published:=true+&&+sortable_stock:>=0&sort_by=title_sortable:asc&page=1&per_page=5&text_match_type=max_weight&q=JCB+round+Air+Vent" \ | |
-X GET \ | |
-H "Content-Type: application/json" \ | |
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export TYPESENSE_API_KEY=xyz | |
mkdir $(pwd)/typesense-data | |
docker run -p 8108:8108 \ | |
-v$(pwd)/typesense-data:/data typesense/typesense:0.25.1 \ | |
--data-dir /data \ | |
--api-key=$TYPESENSE_API_KEY \ | |
--enable-cors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment