# How to do python analysis on elastic dashboard after applying filters using KQL

**URL:** <https://discuss.elastic.co/t/how-to-do-python-analysis-on-elastic-dashboard-after-applying-filters-using-kql/309594>\
**Category:** Elasticsearch\
**Created:** [July 14, 2022, 2:18am UTC](https://discuss.elastic.co/t/how-to-do-python-analysis-on-elastic-dashboard-after-applying-filters-using-kql/309594 "2022-07-14T02:18:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Betty\_Tian](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/betty_tian/32/99284_2.png) [@Betty\_Tian](https://discuss.elastic.co/u/Betty_Tian)\
**Post date:** [July 14, 2022, 2:18am UTC](https://discuss.elastic.co/t/how-to-do-python-analysis-on-elastic-dashboard-after-applying-filters-using-kql/309594/1 "2022-07-14T02:18:52Z")

</div>

For example, i have created a dashboard with many plots built on index A\*, then i applied one filter by clicking on a bar chart.  
(1) How can i export the filtered dataset into python and do some NLP analysis there?  
(2)Even one step further - how to reflect the NLP result on the dashboard on a timely basis? like a dynamic word list? Currently i used markdown to show my still result, but it will not be refreshed when users applied a new filter on the dashboard.

```auto
response = es.search(
    index='A*',
    body={},
    size=total_docs
)

elastic_docs = response["hits"]["hits"]

#extract data from list of nested dictionaries
new_list=[i['_source'] for i in elastic_docs]
new_list_a=pandas.DataFrame(new_list)

df=new_list_a.loc[:,'text']

#generate my word list
word_list=generate_wl(df)

```

Currently the queries selected by users are not reflected on index A\*, so the result is not automatically refreshed/ trigged by any action on the dashboard. Any guidances here will be appreciated!

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [July 20, 2022, 6:47pm UTC](https://discuss.elastic.co/t/how-to-do-python-analysis-on-elastic-dashboard-after-applying-filters-using-kql/309594/2 "2022-07-20T18:47:36Z")

</div>

Hi @Betty_Tian Welcome to the community.

Unfortunately I am not a python expert but perhaps someone else is.

_(1) How can i export the filtered dataset into python and do some NLP analysis there?_

In General you will use the scroll api to scroll through the documents from a search  
See [here](https://elasticsearch-py.readthedocs.io/en/v8.3.2/api.html#async-search)

Here is another example : [How to Paginate/Scroll Elasticsearch Data using Python - Simplernerd](https://simplernerd.com/elasticsearch-scroll-python/)

I think you can find some other example if you search for : elastcisearch python scroll

_(2)Even one step further - how to reflect the NLP result on the dashboard on a timely basis? like a dynamic word list? Currently i used markdown to show my still result, but it will not be refreshed when users applied a new filter on the dashboard._

I am not clear on what you are actually doing? Can you provide more details? Where is this dashboard displayed in Kibana or some other tool?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 17, 2022, 6:48pm UTC](https://discuss.elastic.co/t/how-to-do-python-analysis-on-elastic-dashboard-after-applying-filters-using-kql/309594/3 "2022-08-17T18:48:18Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
