|
| 1 | +<p align="center"><img src="https://github.com/swiftype/swiftype-app-search-python/blob/master/logo-app-search.png?raw=true" alt="Elastic App Search Logo"></p> |
| 2 | + |
| 3 | +<p align="center"><a href="https://circleci.com/gh/swiftype/swiftype-app-search-python"><img src="https://circleci.com/gh/swiftype/swiftype-app-search-python.svg?style=svg" alt="CircleCI buidl"></a> |
| 4 | +<a href="https://github.com/swiftype/swiftype-app-search-python/releases"><img src="https://img.shields.io/github/release/swiftype/swiftype-app-search-python/all.svg?style=flat-square" alt="GitHub release" /></a></p> |
| 5 | + |
| 6 | +> A first-party Python client for building excellent, relevant search experiences with [Elastic App Search](https://www.elastic.co/cloud/app-search-service). |
| 7 | +
|
| 8 | +## Contents |
| 9 | + |
| 10 | ++ [Getting started](#getting-started-) |
| 11 | ++ [Dependencies](#dependencies) |
| 12 | ++ [Usage](#usage) |
| 13 | ++ [Running tests](#running-tests) |
| 14 | ++ [FAQ](#faq-) |
| 15 | ++ [Contribute](#contribute-) |
| 16 | ++ [License](#license-) |
| 17 | + |
| 18 | +*** |
| 19 | + |
| 20 | +## Getting started 🐣 |
| 21 | + |
| 22 | +To install the client, use pip: |
| 23 | + |
| 24 | +```python |
| 25 | +python -m pip install swiftype_app_search |
| 26 | +``` |
| 27 | + |
| 28 | +You can also download the project source and run:: |
| 29 | + |
| 30 | +```python |
| 31 | +python setup.py install |
| 32 | +``` |
| 33 | + |
| 34 | +## Dependencies |
| 35 | + |
| 36 | ++ Python 2.7 / Python 3.3 |
| 37 | ++ [Requests](https://github.com/requests/requests) |
| 38 | ++ [PyJWT](https://github.com/jpadilla/pyjwt) |
| 39 | + |
| 40 | +## Usage |
| 41 | + |
| 42 | +### Instantiating a client |
| 43 | + |
| 44 | +```python |
| 45 | +>>> from swiftype_app_search import Client |
| 46 | +>>> host_identifier = 'host-c5s2mj' |
| 47 | +>>> api_key = 'private-mu75psc5egt9ppzuycnc2mc3' |
| 48 | +>>> client = Client(host_identifier, api_key) |
| 49 | +``` |
| 50 | + |
| 51 | +### Using with App Search Managed Deploys |
| 52 | + |
| 53 | +The client can be configured to use a managed deploy by adjusting the `base_endpoint` and `use_https` parameters. Since managed deploys do not rely on a `host_identifier`, it can be omitted. |
| 54 | + |
| 55 | +```python |
| 56 | +>>> from swiftype_app_search import Client |
| 57 | +>>> client = Client(api_key='private-mu75psc5egt9ppzuycnc2mc3', base_endpoint='localhost:3002/api/as/v1', use_https=False) |
| 58 | +``` |
| 59 | + |
| 60 | +### Index multiple document |
| 61 | + |
| 62 | +```python |
| 63 | +>>> engine_name = 'favorite-videos' |
| 64 | +>>> document = { |
| 65 | + 'id': 'INscMGmhmX4', |
| 66 | + 'url': 'https://www.youtube.com/watch?v=INscMGmhmX4', |
| 67 | + 'title': 'The Original Grumpy Cat', |
| 68 | + 'body': 'A wonderful video of a magnificent cat.' |
| 69 | + } |
| 70 | +>>> client.index_document(engine_name, document) |
| 71 | +{'id': 'INscMGmhmX4'} |
| 72 | +``` |
| 73 | + |
| 74 | +### Index documents |
| 75 | + |
| 76 | +```python |
| 77 | +>>> engine_name = 'favorite-videos' |
| 78 | +>>> documents = [ |
| 79 | + { |
| 80 | + 'id': 'INscMGmhmX4', |
| 81 | + 'url': 'https://www.youtube.com/watch?v=INscMGmhmX4', |
| 82 | + 'title': 'The Original Grumpy Cat', |
| 83 | + 'body': 'A wonderful video of a magnificent cat.' |
| 84 | + }, |
| 85 | + { |
| 86 | + 'id': 'JNDFojsd02', |
| 87 | + 'url': 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', |
| 88 | + 'title': 'Another Grumpy Cat', |
| 89 | + 'body': 'A great video of another cool cat.' |
| 90 | + } |
| 91 | +] |
| 92 | + |
| 93 | +>>> client.index_documents(engine_name, documents) |
| 94 | +[{'id': 'INscMGmhmX4', 'errors': []}, {'id': 'JNDFojsd02', 'errors': []}] |
| 95 | +``` |
| 96 | + |
| 97 | +### Get Documents |
| 98 | + |
| 99 | +```python |
| 100 | +>>> engine_name = 'favorite-videos' |
| 101 | +>>> client.get_documents(engine_name, ['INscMGmhmX4']) |
| 102 | +[{'id': 'INscMGmhmX4','url': 'https://www.youtube.com/watch?v=INscMGmhmX4','title': 'The Original Grumpy Cat','body': 'A wonderful video of a magnificent cat.'}] |
| 103 | +``` |
| 104 | + |
| 105 | +### Destroy Documents |
| 106 | + |
| 107 | +```python |
| 108 | +>>> engine_name = 'favorite-videos' |
| 109 | +>>> client.destroy_documents(engine_name, ['INscMGmhmX4']) |
| 110 | +[{'id': 'INscMGmhmX4','result': True}] |
| 111 | +``` |
| 112 | + |
| 113 | +### List Engines |
| 114 | + |
| 115 | +```python |
| 116 | +>>> client.list_engines(current=1, size=20) |
| 117 | +{ |
| 118 | + 'meta': { |
| 119 | + 'page': { |
| 120 | + 'current': 1, |
| 121 | + 'total_pages': 1, |
| 122 | + 'total_results': 2, |
| 123 | + 'size': 20 |
| 124 | + } |
| 125 | + }, |
| 126 | + 'results': [{'name': 'favorite-videos'}, {'name': 'another-engine'}] |
| 127 | +} |
| 128 | +``` |
| 129 | + |
| 130 | +### Get an Engine |
| 131 | + |
| 132 | +```python |
| 133 | +>>> client.get_engine('favorite-videos') |
| 134 | +{'name': 'favorite-videos'} |
| 135 | +``` |
| 136 | + |
| 137 | +### Create an Engine |
| 138 | + |
| 139 | +```python |
| 140 | +>>> client.create_engine('favorite-videos') |
| 141 | +{'name': 'favorite-videos'} |
| 142 | +``` |
| 143 | + |
| 144 | +### Destroy an Engine |
| 145 | + |
| 146 | +```python |
| 147 | +>>> client.destroy_engine('favorite-videos') |
| 148 | +{'deleted': True} |
| 149 | +``` |
| 150 | + |
| 151 | +### Running search |
| 152 | + |
| 153 | +```python |
| 154 | +>>> client.search('favorite-videos', 'grumpy cat', {}) |
| 155 | +{'meta': {'page': {'current': 1, 'total_pages': 1, 'total_results': 2, 'size': 10}, ...}, 'results': [...]} |
| 156 | +``` |
| 157 | + |
| 158 | +### Create a Signed Search Key |
| 159 | + |
| 160 | +Creating a search key that will only search over the body field. |
| 161 | + |
| 162 | +```python |
| 163 | +>>> api_key = 'private-mu75psc5egt9ppzuycnc2mc3' |
| 164 | +>>> api_key_name = 'my-api-token' |
| 165 | +>>> signed_search_key = Client.create_signed_search_key(api_key, api_key_name, {'search_fields': { 'body': {}}}) |
| 166 | +>>> client = Client(host_identifier, signed_search_key) |
| 167 | +``` |
| 168 | + |
| 169 | +## Running tests |
| 170 | + |
| 171 | +```python |
| 172 | +python setup.py test |
| 173 | +``` |
| 174 | + |
| 175 | +## FAQ 🔮 |
| 176 | + |
| 177 | +### Where do I report issues with the client? |
| 178 | + |
| 179 | +If something is not working as expected, please open an [issue](https://github.com/swiftype/swiftype-app-search-python/issues/new). |
| 180 | + |
| 181 | +### Where can I learn more about App Search? |
| 182 | + |
| 183 | +Your best bet is to read the [documentation](https://swiftype.com/documentation/app-search). |
| 184 | + |
| 185 | +### Where else can I go to get help? |
| 186 | + |
| 187 | +You can checkout the [Elastic App Search community discuss forums](https://discuss.elastic.co/c/app-search). |
| 188 | + |
| 189 | +## Contribute 🚀 |
| 190 | + |
| 191 | +We welcome contributors to the project. Before you begin, a couple notes... |
| 192 | + |
| 193 | ++ Prior to opening a pull request, please create an issue to [discuss the scope of your proposal](https://github.com/swiftype/swiftype-app-search-python/issues). |
| 194 | ++ Please write simple code and concise documentation, when appropriate. |
| 195 | + |
| 196 | +## License 📗 |
| 197 | + |
| 198 | +[MIT](https://github.com/swiftype/swiftype-app-search-python/blob/master/LICENSE.txt) © [Elastic](https://github.com/elastic) |
| 199 | + |
| 200 | +Thank you to all the [contributors](https://github.com/swiftype/swiftype-app-search-python/graphs/contributors)! |
0 commit comments