Moving your project from
pyelasticsearch is easy, especially
for simple use cases. Here are some code changes that will aid your porting.
requests1.x. Breaking changes were introduced in
requests1.0, so if your project was using a previous version, you may need to update your code. Most likely, you just need to change
Instantiating the client should be as simple as changing the invocation…
pyelasticsearchhas no method
create_index_if_missing. Instead, you’ll need catch the exception manually:
try: connection.create_index(index='already_existing_index') except pyelasticsearch.IndexAlreadyExistsError as ex: print 'Index already exists, moving on...'
Instead of using
send_request(). This also requires the path to be passed as an iterable instead of a string. For example…
es._send_request('POST', 'my_index/my_doc_type', body)
connection.send_request('POST', ['my_index', 'my_doc_type'], body)
indiceskeyword argument in
pyelasticsearch, whether the method takes multiple indices or not.
doc_typeskeyword argument in
ElasticHttpNotFoundErrorif the requested documents are not found.
pyesexpects arguments to
indexto be in a different order than our
index(). The document to be indexed needs to be moved from the first positional argument to the third.
send_request()will raise an error if the response can’t be converted to JSON. If you expect that a response will not be JSON, catch the exception and inspect the status code. For example…
connection = ElasticSearch(host) try: # Check for the existence of the "pycon" index: connection.send_request('HEAD', ['pycon']) except InvalidJsonResponseError as exc: if exc.response.status_code == 200: print 'The index exists!'
pyes, you can use
search()and, if necessary, rename the keyword arguments.