# ElasticsearchChatMessageHistory

> **Class** in `langchain_community`

📖 [View in docs](https://reference.langchain.com/python/langchain-community/chat_message_histories/elasticsearch/ElasticsearchChatMessageHistory)

Chat message history that stores history in Elasticsearch.

## Signature

```python
ElasticsearchChatMessageHistory(
    self,
    index: str,
    session_id: str,
    *,
    es_connection: Optional[Elasticsearch] = None,
    es_url: Optional[str] = None,
    es_cloud_id: Optional[str] = None,
    es_user: Optional[str] = None,
    es_api_key: Optional[str] = None,
    es_password: Optional[str] = None,
    ensure_ascii: Optional[bool] = True,
)
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `es_url` | `Optional[str]` | No | URL of the Elasticsearch instance to connect to. (default: `None`) |
| `es_cloud_id` | `Optional[str]` | No | Cloud ID of the Elasticsearch instance to connect to. (default: `None`) |
| `es_user` | `Optional[str]` | No | Username to use when connecting to Elasticsearch. (default: `None`) |
| `es_password` | `Optional[str]` | No | Password to use when connecting to Elasticsearch. (default: `None`) |
| `es_api_key` | `Optional[str]` | No | API key to use when connecting to Elasticsearch. (default: `None`) |
| `es_connection` | `Optional[Elasticsearch]` | No | Optional pre-existing Elasticsearch connection. (default: `None`) |
| `ensure_ascii` | `Optional[bool]` | No | Used to escape ASCII symbols in json.dumps. Defaults to True. (default: `True`) |
| `index` | `str` | Yes | Name of the index to use. |
| `session_id` | `str` | Yes | Arbitrary key that is used to store the messages of a single chat session. |

## Extends

- `BaseChatMessageHistory`

## Constructors

```python
__init__(
    self,
    index: str,
    session_id: str,
    *,
    es_connection: Optional[Elasticsearch] = None,
    es_url: Optional[str] = None,
    es_cloud_id: Optional[str] = None,
    es_user: Optional[str] = None,
    es_api_key: Optional[str] = None,
    es_password: Optional[str] = None,
    ensure_ascii: Optional[bool] = True,
)
```

| Name | Type |
|------|------|
| `index` | `str` |
| `session_id` | `str` |
| `es_connection` | `Optional[Elasticsearch]` |
| `es_url` | `Optional[str]` |
| `es_cloud_id` | `Optional[str]` |
| `es_user` | `Optional[str]` |
| `es_api_key` | `Optional[str]` |
| `es_password` | `Optional[str]` |
| `ensure_ascii` | `Optional[bool]` |


## Properties

- `index`
- `session_id`
- `ensure_ascii`
- `client`
- `messages`

## Methods

- [`get_user_agent()`](https://reference.langchain.com/python/langchain-community/chat_message_histories/elasticsearch/ElasticsearchChatMessageHistory/get_user_agent)
- [`connect_to_elasticsearch()`](https://reference.langchain.com/python/langchain-community/chat_message_histories/elasticsearch/ElasticsearchChatMessageHistory/connect_to_elasticsearch)
- [`add_message()`](https://reference.langchain.com/python/langchain-community/chat_message_histories/elasticsearch/ElasticsearchChatMessageHistory/add_message)
- [`clear()`](https://reference.langchain.com/python/langchain-community/chat_message_histories/elasticsearch/ElasticsearchChatMessageHistory/clear)

## ⚠️ Deprecated

Deprecated since version 0.0.27. Use Use langchain-elasticsearch package instead.

---

[View source on GitHub](https://github.com/langchain-ai/langchain-community/blob/a6a6079511ac8a5c1293337f88096b8641562e77/libs/community/langchain_community/chat_message_histories/elasticsearch.py#L20)