ElasticsearchDatabaseChain SerializationError
Labels: name: auto:bug, name: area: models, name: integration: elasticsearch

### System Info

Using `langchain==0.0.300`

### Who can help?

_No response_

### Information

- [X] The official example notebooks/scripts
- [x] My own modified scripts

### Related Components

- [X] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [ ] Vector Stores / Retrievers
- [ ] Memory
- [ ] Agents / Agent Executors
- [ ] Tools / Toolkits
- [X] Chains
- [ ] Callbacks/Tracing
- [ ] Async

### Reproduction

I tried running the [ElasticsearchDatabaseChain](https://python.langchain.com/docs/use_cases/qa_structured/sql#elastic-search) on a simple Elasticsearch database that contains one index as defined below, but I always get a `SerializationError` due to some faulty json.

Here are the details:

1. Get a local Elasticsearch instance running

```
docker run -p 9200:9200 -e "discovery.type=single-node" -e "xpack.security.enabled=false" -e "xpack.security.http.ssl.enabled=false" docker.elastic.co/elasticsearch/elasticsearch:8.10.2
```

2. Create the index mapping as follows

```bash
curl --request PUT \
  --url 'http://localhost:9200/products-index?pretty=' \
  --header 'content-type: application/json' \
  --header 'user-agent: vscode-restclient' \
  --data '{"settings": {"index.mapping.coerce": false},"mappings": {"properties": {"name": { "type": "text" },"price": { "type": "double" },"reviews": { "type": "text" },"createdAt": { "type": "date", "format": "epoch_second" }},"dynamic": true}}'
```

3. Bulk insert some data

```bash
curl --request POST \
  --url http://localhost:9200/_bulk \
  --header 'content-type: application/x-ndjson' \
  --header 'user-agent: vscode-restclient' \
  --data '{ "index": { "_index": "products-index" } }{ "name": "Bulk Item 666", "price": 666, "reviews": ["Good"], "createdAt": 1697213529 }{ "index": { "_index": "products-index" } }{ "name": "Bulk Item 123", "price": 123, "reviews": ["Good"], "createdAt": 1697213529 }'
```

4. Create and run the chain

```python
from elasticsearch import Elasticsearch
from langchain import OpenAI
from langchain.chains.elasticsearch_database import ElasticsearchDatabaseChain

db = Elasticsearch("http://localhost:9200")
chain = ElasticsearchDatabaseChain.from_llm(
    llm=OpenAI(),
    database=db,
    verbose=True,
)

result = chain.run(prompt)
print(result)
```

<details>
  <summary>Traceback (most recent call last):</summary>

> File "/home/sindeavour/Documents/github/sinaapps/datavacuum-old/ai-service/src/routes/v1/elastic.py", line 82, in elastic
    result = chain.run(prompt)
             ^^^^^^^^^^^^^^^^^
  File "/home/sindeavour/.pyenv/versions/3.11.5/envs/ai-service/lib/python3.11/site-packages/langchain/chains/base.py", line 487, in run
    return self(args[0], callbacks=callbacks, tags=tags, metadata=metadata)[
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sindeavour/.pyenv/versions/3.11.5/envs/ai-service/lib/python3.11/site-packages/langchain/chains/base.py", line 292, in __call__
    raise e
  File "/home/sindeavour/.pyenv/versions/3.11.5/envs/ai-service/lib/python3.11/site-packages/langchain/chains/base.py", line 286, in __call__
    self._call(inputs, run_manager=run_manager)
  File "/home/sindeavour/.pyenv/versions/3.11.5/envs/ai-service/lib/python3.11/site-packages/langchain/chains/elasticsearch_database/base.py", line 127, in _call
    indices_info = self._get_indices_infos(indices)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sindeavour/.pyenv/versions/3.11.5/envs/ai-service/lib/python3.11/site-packages/langchain/chains/elasticsearch_database/base.py", line 100, in _get_indices_infos
    hits = self.database.search(
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/sindeavour/.pyenv/versions/3.11.5/envs/ai-service/lib/python3.11/site-packages/elasticsearch/_sync/client/utils.py", line 414, in wrapped
    return api(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/sindeavour/.pyenv/versions/3.11.5/envs/ai-service/lib/python3.11/site-packages/elasticsearch/_sync/client/__init__.py", line 3924, in search
    return self.perform_request(  # type: ignore[return-value]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sindeavour/.pyenv/versions/3.11.5/envs/ai-service/lib/python3.11/site-packages/elasticsearch/_sync/client/_base.py", line 285, in perform_request
    meta, resp_body = self.transport.perform_request(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sindeavour/.pyenv/versions/3.11.5/envs/ai-service/lib/python3.11/site-packages/elastic_transport/_transport.py", line 347, in perform_request
    data = self.serializers.loads(raw_data, meta.mimetype)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sindeavour/.pyenv/versions/3.11.5/envs/ai-service/lib/python3.11/site-packages/elastic_transport/_serializer.py", line 196, in loads
    return self.get_serializer(mimetype).loads(data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sindeavour/.pyenv/versions/3.11.5/envs/ai-service/lib/python3.11/site-packages/elastic_transport/_serializer.py", line 95, in loads
    raise SerializationError(
elastic_transport.SerializationError: Unable to deserialize as JSON: b'{"took":1,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":4,"relation":"eq"},"max_score":1.0,"hits":[{"_index":"products-index","_id":"1","_score":1.0,"_source":{\n    "name": "Samsung S22 Ultra",\n    "price": 975.99,\n    "reviews": ["Good"],\n    "createdAt": 1697145247 // epoch_second\n}},{"_index":"products-index","_id":"pRG9JYsB0QTitqW3X0qT","_score":1.0,"_source":{\n    "name": "iPhone 14 Pro",\n    "price": 1099,\n    "reviews": ["Good"],\n    "createdAt":  1697145249 // epoch_second\n}},{"_index":"products-index","_id":"phG9JYsB0QTitqW3ZEq5","_score":1.0,"_source":{ "name": "Bulk Item 666", "price": 666, "reviews": ["Good"], "createdAt": 1697145250 }}]}}'

</details>


```
elastic_transport.SerializationError: Unable to deserialize as JSON: b'{"took":0,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":4,"relation":"eq"},"max_score":1.0,"hits":[{"_index":"products-index","_id":"1","_score":1.0,"_source":{\n    "name": "Samsung S22 Ultra",\n    "price": 975.99,\n    "reviews": ["Good"],\n    "createdAt": 1697145247 // epoch_second\n}},{"_index":"products-index","_id":"pRG9JYsB0QTitqW3X0qT","_score":1.0,"_source":{\n    "name": "iPhone 14 Pro",\n    "price": 1099,\n    "reviews": ["Good"],\n    "createdAt":  1697145249 // epoch_second\n}},{"_index":"products-index","_id":"phG9JYsB0QTitqW3ZEq5","_score":1.0,"_source":{ "name": "Bulk Item 666", "price": 666, "reviews": ["Good"], "createdAt": 1697145250 }}]}}'
```

If you look closely, you can see that there is an invalid comment `// epoch_second` in multiple places in the generated json, hence why the parsing fails. 


### Expected behavior

The chain should run without issues when executing `chain.run(prompt)`