Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
A Deprecated API client for Swiftype App Search - Use new elastic-app-search package instead.
⚠️ This repository is deprecated ⚠️
Please visit https://github.com/elastic/app-search-python for the up to date version. Thank you! - Elastic
A first-party Python client for building excellent, relevant search experiences with Elastic App Search.
To install the client, use pip:
python -m pip install swiftype_app_search
You can also download the project source and run::
python setup.py install
>>> from swiftype_app_search import Client
>>> host_identifier = 'host-c5s2mj'
>>> api_key = 'private-mu75psc5egt9ppzuycnc2mc3'
>>> client = Client(host_identifier, api_key)
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.
>>> from swiftype_app_search import Client
>>> client = Client(
api_key='private-mu75psc5egt9ppzuycnc2mc3',
base_endpoint='localhost:3002/api/as/v1',
use_https=False
)
>>> engine_name = 'favorite-videos'
>>> document = {
'id': 'INscMGmhmX4',
'url': 'https://www.youtube.com/watch?v=INscMGmhmX4',
'title': 'The Original Grumpy Cat',
'body': 'A wonderful video of a magnificent cat.'
}
>>> client.index_document(engine_name, document)
{'id': 'INscMGmhmX4'}
>>> engine_name = 'favorite-videos'
>>> documents = [
{
'id': 'INscMGmhmX4',
'url': 'https://www.youtube.com/watch?v=INscMGmhmX4',
'title': 'The Original Grumpy Cat',
'body': 'A wonderful video of a magnificent cat.'
},
{
'id': 'JNDFojsd02',
'url': 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
'title': 'Another Grumpy Cat',
'body': 'A great video of another cool cat.'
}
]
>>> client.index_documents(engine_name, documents)
[{'id': 'INscMGmhmX4', 'errors': []}, {'id': 'JNDFojsd02', 'errors': []}]
>>> engine_name = 'favorite-videos'
>>> documents = [
{
'id': 'INscMGmhmX4',
'title': 'Updated title'
}
]
>>> client.update_documents(engine_name, documents)
>>> engine_name = 'favorite-videos'
>>> client.get_documents(engine_name, ['INscMGmhmX4'])
[{'id': 'INscMGmhmX4','url': 'https://www.youtube.com/watch?v=INscMGmhmX4','title': 'The Original Grumpy Cat','body': 'A wonderful video of a magnificent cat.'}]
>>> engine_name = 'favorite-videos'
>>> client.list_documents(engine_name, current=1, size=20)
{
'meta': {
'page': {
'current': 1,
'total_pages': 1,
'total_results': 2,
'size': 20
}
},
'results': [{'id': 'INscMGmhmX4','url': 'https://www.youtube.com/watch?v=INscMGmhmX4','title': 'The Original Grumpy Cat','body': 'A wonderful video of a magnificent cat.'}]
}
>>> engine_name = 'favorite-videos'
>>> client.destroy_documents(engine_name, ['INscMGmhmX4'])
[{'id': 'INscMGmhmX4','result': True}]
>>> engine_name = 'favorite-videos'
>>> client.get_schema(engine_name)
{'name':'text', 'square_km': 'number', 'square_mi': 'text'}
>>> engine_name = 'favorite-videos'
>>> client.update_schema(engine_name, {'square_km': 'text'})
{'square_km': 'text'}
>>> client.update_schema(engine_name, {'square_mi': 'text'})
{'square_km': 'text', 'square_mi': 'text'}
>>> client.update_schema(engine_name, {'square_km': 'number'})
{'square_km': 'number', 'square_mi': 'text'}
>>> client.list_engines(current=1, size=20)
{
'meta': {
'page': {
'current': 1,
'total_pages': 1,
'total_results': 2,
'size': 20
}
},
'results': [{'name': 'favorite-videos'}, {'name': 'another-engine'}]
}
>>> client.get_engine('favorite-videos')
{'name': 'favorite-videos'}
>>> client.create_engine('favorite-videos', 'en')
{'name': 'favorite-videos', 'type': 'default', 'language': 'en'}
>>> client.destroy_engine('favorite-videos')
{'deleted': True}
>>> client.search('favorite-videos', 'grumpy cat', {})
{'meta': {'page': {'current': 1, 'total_pages': 1, 'total_results': 2, 'size': 10}, ...}, 'results': [...]}
>>> client.multi_search('favorite-videos', [{
'query': 'cat',
'options': { 'search_fields': { 'title': {} }}
},{
'query': 'dog',
'options': { 'search_fields': { 'body': {} }}
}])
[{'meta': {...}, 'results': [...]}, {'meta': {...}, 'results': [...]}]
>>> client.query_suggestion('favorite-videos', 'cat', {
'size': 10,
'types': {
'documents': {
'fields': ['title']
}
}
})
{'results': {'documents': [{'suggestion': 'cat'}]}, 'meta': {'request_id': '390be384ad5888353e1b32adcfaaf1c9'}}
>>> client.click(engine_name, {'query': 'cat', 'document_id': 'INscMGmhmX4'})
Creating a search key that will only search over the body field.
>>> api_key = 'private-mu75psc5egt9ppzuycnc2mc3'
>>> api_key_name = 'my-api-token'
>>> signed_search_key = Client.create_signed_search_key(api_key, api_key_name, {'search_fields': { 'body': {}}})
>>> client = Client(host_identifier, signed_search_key)
python setup.py test
If something is not working as expected, please open an issue.
Your best bet is to read the documentation.
You can checkout the Elastic App Search community discuss forums.
We welcome contributors to the project. Before you begin, a couple notes:
Thank you to all the contributors!
FAQs
A Deprecated API client for Swiftype App Search - Use new elastic-app-search package instead.
We found that swiftype-app-search demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.