# How to use streamlit with elasticsearch?

**URL:** <https://discuss.streamlit.io/t/how-to-use-streamlit-with-elasticsearch/24038>\
**Category:** Using Streamlit\
**Created:** [April 11, 2022, 11:13am UTC](https://discuss.streamlit.io/t/how-to-use-streamlit-with-elasticsearch/24038 "2022-04-11T11:13:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![creativitylab](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/creativitylab/32/14676_2.png) [@creativitylab](https://discuss.streamlit.io/u/creativitylab)\
**Post date:** [April 11, 2022, 11:13am UTC](https://discuss.streamlit.io/t/how-to-use-streamlit-with-elasticsearch/24038/1 "2022-04-11T11:13:31Z")

</div>

I want to authenticate in elasticsearch using streamlit and to change the query after authentication, depending on the selected values from some dropdowns. How to achieve this?

I tried:

```auto
@st.experimental_memo(ttl=600)
def get_es_result(username='user', password='pass'):

    es = Elasticsearch(['https://elastic-endpoint/'],
                       http_auth=(username, password))
    return es

```

But this triggers:

```auto
TypeError: can't pickle _thread.lock objects

```

In the python app I’m calling the above method like:

```auto
def app():
    st.title('Home')

    es = get_es_result()
    df = pd.DataFrame()

    query = {
        "range": {"TimeStamp": {"gte": "now-10d/d", "format": "epoch_millis"}}
    }
    result = es.search(index="test-index", size=10000, body=
    {
        "query": query
    }

                       )

```

How could I cache the authentication to the elasticsearch so that it happens only once and then query the data?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/streamlit/original/3X/c/f/cf4c2ee0d938358f82448c5fe4b9c3c91d7ce19c.svg) [@system](https://discuss.streamlit.io/u/system)\
**Post date:** [April 11, 2023, 11:13am UTC](https://discuss.streamlit.io/t/how-to-use-streamlit-with-elasticsearch/24038/2 "2023-04-11T11:13:37Z")

</div>

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