-
Notifications
You must be signed in to change notification settings - Fork 14.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding ElasticserachPythonHook - ES Hook With The Python Client #24895
Adding ElasticserachPythonHook - ES Hook With The Python Client #24895
Conversation
@@ -0,0 +1,56 @@ | |||
# |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we have two ways to interact with elastic one is Python based with the SDK and one is SQL based by using sql query syntax.
i think we should rename this file as python.py
or something similar?
and the current ElasticsearchHook
in hooks/elasticsearch.py
class ElasticsearchHook(DbApiHook): |
ElasticsearchSqlHook
Alternatively, we can have both classes ElasticsearchSqlHook
+ ElasticsearchPythonHook
in the same hooks/elasticsearch.py
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will add them to the same files, as I think having a file named python.py
is a bit confusing..
I don't know how it will play with the documentation files, but I'll try to make it work :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done :)
from airflow.models import Connection | ||
from airflow.providers.elasticsearch.hooks.elasticsearch import ElasticsearchHook | ||
from airflow.providers.elasticsearch.hooks.elasticsearch import ElasticsearchHook, ElasticsearchPythonHook |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the new class name on the import
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done- the old hook tests are now using the new name.
I've also added a test that checks the generation of a DepracationWarning for ElasticsearchHook
:)
:param hosts: list: A list of a single or many Elasticsearch instances. Example: ["http://localhost:9200"] | ||
:param es_conn_args: dict: Additional arguments you might need to enter to connect to Elasticsearch. | ||
Example: {"ca_cert":"/path/to/http_ca.crt", "basic_auth": "(user, pass)"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we need also a connection.rst to explain this additional settings for the connection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a new document for both hooks under hooks/elasticsearch.rst
@@ -0,0 +1,58 @@ | |||
# Licensed to the Apache Software Foundation (ASF) under one |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename the file example_elasticsearch_hook.py ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've merged the new example into the old examples file :)
Now it should give the example to both hooks
Docs now :( |
@potiuk Is it possible to get your assistance on the failing tests?
Sorry for the trouble :( I'm just kinda stuck and need an external opinion 🙏 |
5100406
to
fa9d058
Compare
|
Look at the tests - there some other deprecated classes there mentioned in the exclusion list. |
Wow I completely missed the |
…c/airflow into adding_elasticsearch_python_hook
@potiuk Sorry to trouble you again.. I followed your tips, and now the integration tests are passing! But the build docs are still failing on the same thing - Really appreciate your help 🙏 |
Well. Not sure - seems like really "cryptic" error from Sphinx (which is known from rather cryptic messages). Look at the actual output of the sphix build (Above the summary) and you will find the warning there. Also there is apparently a bug (@mik-laj?) that in this case our error parsing added second .rst to display the line of .rst file that was actually causing it. However I made an intelligent guess and looked closely. From what I see, I think the lines below are all indented ONE SPACE MORE than all the others. so maybe fixing that will help.
Also few other tips - and ways I deal with similar cases (been there, done that many times). You can easily iterate locally with it (and this is what I do when I have similar issues with docs):
This will run much faster than CI circle and allows you to also take a look at sphinx-generated intermediate artifacts which usually helps with debugging it. If all else fails. I usually fall-back to just looking at teh source code of Sphins and finding what the error message actually means (i.e. when it will be produced). In this case: |
Finally, all the tests are passing! :D Later, I had issues with a "typo" - but Sphinx just set it as a generic typo, and did not always point to the correct file with the error.. In any case, at least now I know how to handle these issues - the more I know, the more I can help other people in the community :) |
Yeah. quite often the message are rather unhelpful, I must agree. |
Adding a new hook for work with Elasticsearch, using the official Elasticsearch Python client.
Currently, I've implemented only one function (search), but if any more will be needed, we can add even more.
This hook was also tested with a local ES docker image, to make sure that everything works :)
closes: #21929