code: def test_elasticsearch(self):
      from elasticsearch import Elasticsearch
  
      with patch(
          "elasticsearch.Elasticsearch.search"
      ) as mocked_search, patch(
          "elasticsearch.client.IndicesClient.create"
      ) as mocked_index_create, patch(
          "elasticsearch.helpers.streaming_bulk"
      ) as mocked_bulk:
          es_client = Elasticsearch()
          mocked_index_create.return_value = {"acknowledged": True}
          index = ElasticSearchIndex(es_client=es_client)
          mocked_bulk.return_value([(True, None)] * 3)
          index.add_documents(["foo", "bar", "foobar"])
  
          # single query
          query = "foo"
          mocked_search.return_value = {
              "hits": {"hits": [{"_score": 1, "_id": 0}]}
          }
          scores, indices = index.search(query)
          self.assertEqual(scores[0], 1)
          self.assertEqual(indices[0], 0)
  
          # single query with timeout
          query = "foo"
          mocked_search.return_value = {
              "hits": {"hits": [{"_score": 1, "_id": 0}]}
          }
          scores, indices = index.search(query, request_timeout=30)
          self.assertEqual(scores[0], 1)
          self.assertEqual(indices[0], 0)
  
          # batched queries
          queries = ["foo", "bar", "foobar"]
          mocked_search.return_value = {
              "hits": {"hits": [{"_score": 1, "_id": 1}]}
          }
          total_scores, total_indices = index.search_batch(queries)
          best_scores = [scores[0] for scores in total_scores]
          best_indices = [indices[0] for indices in total_indices]
          self.assertGreater(np.min(best_scores), 0)
          self.assertListEqual([1, 1, 1], best_indices)
  
          # batched queries with timeout
          queries = ["foo", "bar", "foobar"]
          mocked_search.return_value = {
              "hits": {"hits": [{"_score": 1, "_id": 1}]}
          }
          total_scores, total_indices = index.search_batch(
              queries, request_timeout=30
          )
          best_scores = [scores[0] for scores in total_scores]
          best_indices = [indices[0] for indices in total_indices]
          self.assertGreater(np.min(best_scores), 0)
          self.assertListEqual([1, 1, 1], best_indices)
  
imports: import os
  import tempfile
  from functools import partial
  from unittest import TestCase
  from unittest.mock import patch
  import numpy
  import pytest
  from datasets.arrow_dataset import Dataset
  from datasets.search import ElasticSearchIndex, FaissIndex, MissingIndex
  from .utils import require_elasticsearch, require_faiss
label_desc: Use image node_id 1 for calling the ElasticSearchIndexTest obj's underlying member method code with example usage: obj.test_elasticsearch() without return types