|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [], |
| 8 | + "source": [ |
| 9 | + "import json\n", |
| 10 | + "import requests\n", |
| 11 | + "from pprint import pprint" |
| 12 | + ] |
| 13 | + }, |
| 14 | + { |
| 15 | + "cell_type": "code", |
| 16 | + "execution_count": null, |
| 17 | + "metadata": {}, |
| 18 | + "outputs": [], |
| 19 | + "source": [ |
| 20 | + "endpoint = 'https://YOUR-SERVICE-NAME.search.windows.net/'\n", |
| 21 | + "api_version = '?api-version=2019-05-06'\n", |
| 22 | + "headers = {'Content-Type': 'application/json',\n", |
| 23 | + " 'api-key': 'YOUR-ADMIN-API-KEY' }" |
| 24 | + ] |
| 25 | + }, |
| 26 | + { |
| 27 | + "cell_type": "code", |
| 28 | + "execution_count": null, |
| 29 | + "metadata": {}, |
| 30 | + "outputs": [], |
| 31 | + "source": [ |
| 32 | + "url = endpoint + \"indexes\" + api_version + \"&$select=name\"\n", |
| 33 | + "response = requests.get(url, headers=headers)\n", |
| 34 | + "index_list = response.json()\n", |
| 35 | + "pprint(index_list)" |
| 36 | + ] |
| 37 | + }, |
| 38 | + { |
| 39 | + "cell_type": "code", |
| 40 | + "execution_count": null, |
| 41 | + "metadata": {}, |
| 42 | + "outputs": [], |
| 43 | + "source": [ |
| 44 | + "index_schema = {\n", |
| 45 | + " \"name\": \"hotels-py\", \n", |
| 46 | + " \"fields\": [\n", |
| 47 | + " {\"name\": \"HotelId\", \"type\": \"Edm.String\", \"key\": \"true\", \"filterable\": \"true\"},\n", |
| 48 | + " {\"name\": \"HotelName\", \"type\": \"Edm.String\", \"searchable\": \"true\", \"filterable\": \"false\", \"sortable\": \"true\", \"facetable\": \"false\"},\n", |
| 49 | + " {\"name\": \"Description\", \"type\": \"Edm.String\", \"searchable\": \"true\", \"filterable\": \"false\", \"sortable\": \"false\", \"facetable\": \"false\", \"analyzer\": \"en.lucene\"},\n", |
| 50 | + " {\"name\": \"Description_fr\", \"type\": \"Edm.String\", \"searchable\": \"true\", \"filterable\": \"false\", \"sortable\": \"false\", \"facetable\": \"false\", \"analyzer\": \"fr.lucene\"},\n", |
| 51 | + " {\"name\": \"Category\", \"type\": \"Edm.String\", \"searchable\": \"true\", \"filterable\": \"true\", \"sortable\": \"true\", \"facetable\": \"true\"},\n", |
| 52 | + " {\"name\": \"Tags\", \"type\": \"Collection(Edm.String)\", \"searchable\": \"true\", \"filterable\": \"true\", \"sortable\": \"false\", \"facetable\": \"true\"},\n", |
| 53 | + " {\"name\": \"ParkingIncluded\", \"type\": \"Edm.Boolean\", \"filterable\": \"true\", \"sortable\": \"true\", \"facetable\": \"true\"},\n", |
| 54 | + " {\"name\": \"LastRenovationDate\", \"type\": \"Edm.DateTimeOffset\", \"filterable\": \"true\", \"sortable\": \"true\", \"facetable\": \"true\"},\n", |
| 55 | + " {\"name\": \"Rating\", \"type\": \"Edm.Double\", \"filterable\": \"true\", \"sortable\": \"true\", \"facetable\": \"true\"},\n", |
| 56 | + " {\"name\": \"Address\", \"type\": \"Edm.ComplexType\", \n", |
| 57 | + " \"fields\": [\n", |
| 58 | + " {\"name\": \"StreetAddress\", \"type\": \"Edm.String\", \"filterable\": \"false\", \"sortable\": \"false\", \"facetable\": \"false\", \"searchable\": \"true\"},\n", |
| 59 | + " {\"name\": \"City\", \"type\": \"Edm.String\", \"searchable\": \"true\", \"filterable\": \"true\", \"sortable\": \"true\", \"facetable\": \"true\"},\n", |
| 60 | + " {\"name\": \"StateProvince\", \"type\": \"Edm.String\", \"searchable\": \"true\", \"filterable\": \"true\", \"sortable\": \"true\", \"facetable\": \"true\"},\n", |
| 61 | + " {\"name\": \"PostalCode\", \"type\": \"Edm.String\", \"searchable\": \"true\", \"filterable\": \"true\", \"sortable\": \"true\", \"facetable\": \"true\"},\n", |
| 62 | + " {\"name\": \"Country\", \"type\": \"Edm.String\", \"searchable\": \"true\", \"filterable\": \"true\", \"sortable\": \"true\", \"facetable\": \"true\"}\n", |
| 63 | + " ]\n", |
| 64 | + " }\n", |
| 65 | + " ]\n", |
| 66 | + "}" |
| 67 | + ] |
| 68 | + }, |
| 69 | + { |
| 70 | + "cell_type": "code", |
| 71 | + "execution_count": null, |
| 72 | + "metadata": {}, |
| 73 | + "outputs": [], |
| 74 | + "source": [ |
| 75 | + "url = endpoint + \"indexes\" + api_version\n", |
| 76 | + "response = requests.post(url, headers=headers, json=index_schema)\n", |
| 77 | + "index = response.json()\n", |
| 78 | + "pprint(index)" |
| 79 | + ] |
| 80 | + }, |
| 81 | + { |
| 82 | + "cell_type": "code", |
| 83 | + "execution_count": null, |
| 84 | + "metadata": {}, |
| 85 | + "outputs": [], |
| 86 | + "source": [ |
| 87 | + "documents = {\n", |
| 88 | + " \"value\": [\n", |
| 89 | + " {\n", |
| 90 | + " \"@search.action\": \"upload\",\n", |
| 91 | + " \"HotelId\": \"1\",\n", |
| 92 | + " \"HotelName\": \"Secret Point Motel\",\n", |
| 93 | + " \"Description\": \"The hotel is ideally located on the main commercial artery of the city in the heart of New York. A few minutes away is Time's Square and the historic centre of the city, as well as other places of interest that make New York one of America's most attractive and cosmopolitan cities.\",\n", |
| 94 | + " \"Description_fr\": \"L'hôtel est idéalement situé sur la principale artère commerciale de la ville en plein cœur de New York. A quelques minutes se trouve la place du temps et le centre historique de la ville, ainsi que d'autres lieux d'intérêt qui font de New York l'une des villes les plus attractives et cosmopolites de l'Amérique.\",\n", |
| 95 | + " \"Category\": \"Boutique\",\n", |
| 96 | + " \"Tags\": [ \"pool\", \"air conditioning\", \"concierge\" ],\n", |
| 97 | + " \"ParkingIncluded\": \"false\",\n", |
| 98 | + " \"LastRenovationDate\": \"1970-01-18T00:00:00Z\",\n", |
| 99 | + " \"Rating\": 3.60,\n", |
| 100 | + " \"Address\": {\n", |
| 101 | + " \"StreetAddress\": \"677 5th Ave\",\n", |
| 102 | + " \"City\": \"New York\",\n", |
| 103 | + " \"StateProvince\": \"NY\",\n", |
| 104 | + " \"PostalCode\": \"10022\",\n", |
| 105 | + " \"Country\": \"USA\"\n", |
| 106 | + " }\n", |
| 107 | + " },\n", |
| 108 | + " {\n", |
| 109 | + " \"@search.action\": \"upload\",\n", |
| 110 | + " \"HotelId\": \"2\",\n", |
| 111 | + " \"HotelName\": \"Twin Dome Motel\",\n", |
| 112 | + " \"Description\": \"The hotel is situated in a nineteenth century plaza, which has been expanded and renovated to the highest architectural standards to create a modern, functional and first-class hotel in which art and unique historical elements coexist with the most modern comforts.\",\n", |
| 113 | + " \"Description_fr\": \"L'hôtel est situé dans une place du XIXe siècle, qui a été agrandie et rénovée aux plus hautes normes architecturales pour créer un hôtel moderne, fonctionnel et de première classe dans lequel l'art et les éléments historiques uniques coexistent avec le confort le plus moderne.\",\n", |
| 114 | + " \"Category\": \"Boutique\",\n", |
| 115 | + " \"Tags\": [ \"pool\", \"free wifi\", \"concierge\" ],\n", |
| 116 | + " \"ParkingIncluded\": \"false\",\n", |
| 117 | + " \"LastRenovationDate\": \"1979-02-18T00:00:00Z\",\n", |
| 118 | + " \"Rating\": 3.60,\n", |
| 119 | + " \"Address\": {\n", |
| 120 | + " \"StreetAddress\": \"140 University Town Center Dr\",\n", |
| 121 | + " \"City\": \"Sarasota\",\n", |
| 122 | + " \"StateProvince\": \"FL\",\n", |
| 123 | + " \"PostalCode\": \"34243\",\n", |
| 124 | + " \"Country\": \"USA\"\n", |
| 125 | + " }\n", |
| 126 | + " },\n", |
| 127 | + " {\n", |
| 128 | + " \"@search.action\": \"upload\",\n", |
| 129 | + " \"HotelId\": \"3\",\n", |
| 130 | + " \"HotelName\": \"Triple Landscape Hotel\",\n", |
| 131 | + " \"Description\": \"The Hotel stands out for its gastronomic excellence under the management of William Dough, who advises on and oversees all of the Hotel’s restaurant services.\",\n", |
| 132 | + " \"Description_fr\": \"L'hôtel est situé dans une place du XIXe siècle, qui a été agrandie et rénovée aux plus hautes normes architecturales pour créer un hôtel moderne, fonctionnel et de première classe dans lequel l'art et les éléments historiques uniques coexistent avec le confort le plus moderne.\",\n", |
| 133 | + " \"Category\": \"Resort and Spa\",\n", |
| 134 | + " \"Tags\": [ \"air conditioning\", \"bar\", \"continental breakfast\" ],\n", |
| 135 | + " \"ParkingIncluded\": \"true\",\n", |
| 136 | + " \"LastRenovationDate\": \"2015-09-20T00:00:00Z\",\n", |
| 137 | + " \"Rating\": 4.80,\n", |
| 138 | + " \"Address\": {\n", |
| 139 | + " \"StreetAddress\": \"3393 Peachtree Rd\",\n", |
| 140 | + " \"City\": \"Atlanta\",\n", |
| 141 | + " \"StateProvince\": \"GA\",\n", |
| 142 | + " \"PostalCode\": \"30326\",\n", |
| 143 | + " \"Country\": \"USA\"\n", |
| 144 | + " }\n", |
| 145 | + " }\n", |
| 146 | + " ]\n", |
| 147 | + "}\n" |
| 148 | + ] |
| 149 | + }, |
| 150 | + { |
| 151 | + "cell_type": "code", |
| 152 | + "execution_count": null, |
| 153 | + "metadata": {}, |
| 154 | + "outputs": [], |
| 155 | + "source": [ |
| 156 | + "url = endpoint + \"indexes/hotels-py/docs/index\" + api_version\n", |
| 157 | + "response = requests.post(url, headers=headers, json=documents)\n", |
| 158 | + "index_content = response.json()\n", |
| 159 | + "pprint(index_content)" |
| 160 | + ] |
| 161 | + }, |
| 162 | + { |
| 163 | + "cell_type": "code", |
| 164 | + "execution_count": null, |
| 165 | + "metadata": {}, |
| 166 | + "outputs": [], |
| 167 | + "source": [ |
| 168 | + "searchstring = '&search=*&$count=true&$select=HotelId,HotelName'" |
| 169 | + ] |
| 170 | + }, |
| 171 | + { |
| 172 | + "cell_type": "code", |
| 173 | + "execution_count": null, |
| 174 | + "metadata": {}, |
| 175 | + "outputs": [], |
| 176 | + "source": [ |
| 177 | + "searchstring = '&search=*&$filter=Rating gt 4&$select=HotelId,HotelName,Description,Rating'" |
| 178 | + ] |
| 179 | + }, |
| 180 | + { |
| 181 | + "cell_type": "code", |
| 182 | + "execution_count": null, |
| 183 | + "metadata": {}, |
| 184 | + "outputs": [], |
| 185 | + "source": [ |
| 186 | + "searchstring = '&search=hotel&$top=2&$select=HotelId,HotelName,Description'" |
| 187 | + ] |
| 188 | + }, |
| 189 | + { |
| 190 | + "cell_type": "code", |
| 191 | + "execution_count": null, |
| 192 | + "metadata": {}, |
| 193 | + "outputs": [], |
| 194 | + "source": [ |
| 195 | + "searchstring = '&search=pool&$orderby=Address/City&$select=HotelId,HotelName,Address/City,Address/StateProvince'" |
| 196 | + ] |
| 197 | + }, |
| 198 | + { |
| 199 | + "cell_type": "code", |
| 200 | + "execution_count": null, |
| 201 | + "metadata": {}, |
| 202 | + "outputs": [], |
| 203 | + "source": [ |
| 204 | + "url = endpoint + \"indexes/hotels-py/docs\" + api_version + searchstring\n", |
| 205 | + "response = requests.get(url, headers=headers, json=searchstring)\n", |
| 206 | + "query = response.json()\n", |
| 207 | + "pprint(query)" |
| 208 | + ] |
| 209 | + }, |
| 210 | + { |
| 211 | + "cell_type": "code", |
| 212 | + "execution_count": null, |
| 213 | + "metadata": {}, |
| 214 | + "outputs": [], |
| 215 | + "source": [ |
| 216 | + "url = endpoint + \"indexes/hotels-py\" + api_version\n", |
| 217 | + "\n", |
| 218 | + "response = requests.delete(url, headers=headers)" |
| 219 | + ] |
| 220 | + }, |
| 221 | + { |
| 222 | + "cell_type": "code", |
| 223 | + "execution_count": null, |
| 224 | + "metadata": {}, |
| 225 | + "outputs": [], |
| 226 | + "source": [ |
| 227 | + "url = endpoint + \"indexes\" + api_version + \"&$select=name\"\n", |
| 228 | + "\n", |
| 229 | + "response = requests.get(url, headers=headers)\n", |
| 230 | + "index_list = response.json()\n", |
| 231 | + "pprint(index_list)" |
| 232 | + ] |
| 233 | + } |
| 234 | + ], |
| 235 | + "metadata": { |
| 236 | + "kernelspec": { |
| 237 | + "display_name": "Python 3", |
| 238 | + "language": "python", |
| 239 | + "name": "python3" |
| 240 | + }, |
| 241 | + "language_info": { |
| 242 | + "codemirror_mode": { |
| 243 | + "name": "ipython", |
| 244 | + "version": 3 |
| 245 | + }, |
| 246 | + "file_extension": ".py", |
| 247 | + "mimetype": "text/x-python", |
| 248 | + "name": "python", |
| 249 | + "nbconvert_exporter": "python", |
| 250 | + "pygments_lexer": "ipython3", |
| 251 | + "version": "3.7.3" |
| 252 | + } |
| 253 | + }, |
| 254 | + "nbformat": 4, |
| 255 | + "nbformat_minor": 2 |
| 256 | +} |
0 commit comments