This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new a0a05ff  Adds example showing the ES_hook (#17944)
a0a05ff is described below

commit a0a05ffeddab54199e43b76016703c7ccaed3cd1
Author: Frank Cash <[email protected]>
AuthorDate: Sat Sep 4 15:48:31 2021 -0400

    Adds example showing the ES_hook (#17944)
    
    * Adds example showing the ES_hook
    
    adds comment
    
    * reformats code
    
    * Black formatting
    
    * airflow.operators.python_operator -> airflow.operators.python
    
    * Updates docs to reference example DAGs
---
 .../elasticsearch/example_dags/__init__.py         | 16 ++++++
 .../example_dags/example_elasticsearch_query.py    | 59 ++++++++++++++++++++++
 .../index.rst                                      |  6 +++
 3 files changed, 81 insertions(+)

diff --git a/airflow/providers/elasticsearch/example_dags/__init__.py 
b/airflow/providers/elasticsearch/example_dags/__init__.py
new file mode 100644
index 0000000..13a8339
--- /dev/null
+++ b/airflow/providers/elasticsearch/example_dags/__init__.py
@@ -0,0 +1,16 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
diff --git 
a/airflow/providers/elasticsearch/example_dags/example_elasticsearch_query.py 
b/airflow/providers/elasticsearch/example_dags/example_elasticsearch_query.py
new file mode 100644
index 0000000..b0efea7
--- /dev/null
+++ 
b/airflow/providers/elasticsearch/example_dags/example_elasticsearch_query.py
@@ -0,0 +1,59 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from datetime import datetime, timedelta
+
+from airflow import DAG
+from airflow.operators.python import PythonOperator
+from airflow.providers.elasticsearch.hooks.elasticsearch import 
ElasticsearchHook
+
+
+def show_tables():
+    """
+    show_tables queries elasticsearch to list available tables
+    """
+    es = ElasticsearchHook(elasticsearch_conn_id='production-es')
+
+    # Handle ES conn with context manager
+    with es.get_conn() as es_conn:
+        tables = es_conn.execute('SHOW TABLES')
+        for table, *_ in tables:
+            print(f"table: {table}")
+    return True
+
+
+# Default settings applied to all tasks
+default_args = {
+    'owner': 'airflow',
+    'depends_on_past': False,
+    'email_on_failure': False,
+    'email_on_retry': False,
+    'retries': 1,
+    'retry_delay': timedelta(minutes=5),
+}
+
+# Using a DAG context manager, you don't have to specify the dag property of 
each task
+with DAG(
+    'elasticsearch_dag',
+    start_date=datetime(2021, 8, 30),
+    max_active_runs=1,
+    schedule_interval=timedelta(days=1),
+    default_args=default_args,
+    catchup=False,
+) as dag:
+
+    es_tables = PythonOperator(task_id='es_print_tables', 
python_callable=show_tables)
diff --git a/docs/apache-airflow-providers-elasticsearch/index.rst 
b/docs/apache-airflow-providers-elasticsearch/index.rst
index 578d8d4..fc16855 100644
--- a/docs/apache-airflow-providers-elasticsearch/index.rst
+++ b/docs/apache-airflow-providers-elasticsearch/index.rst
@@ -39,6 +39,12 @@ Content
     :maxdepth: 1
     :caption: Resources
 
+    Example DAGs 
<https://github.com/apache/airflow/tree/main/airflow/providers/elasticsearch/example_dags>
+
+.. toctree::
+    :maxdepth: 1
+    :caption: Resources
+
     PyPI Repository 
<https://pypi.org/project/apache-airflow-providers-elasticsearch/>
 
 .. THE REMAINDER OF THE FILE IS AUTOMATICALLY GENERATED. IT WILL BE 
OVERWRITTEN AT RELEASE TIME!

Reply via email to