class_docstr: Elasticsearch driver for image-match
  
      
code: def search_single_record(self, rec, pre_filter=None):
      path = rec.pop("path")
      signature = rec.pop("signature")
      if "metadata" in rec:
          rec.pop("metadata")
  
      # build the 'should' list
      should = [
          {"term": {"{}.{}".format(self.doc_type, word): rec[word]}}
          for word in rec
      ]
      body = {
          "query": {"bool": {"should": should}},
          "_source": {
              "excludes": ["{}.simple_word_*".format(self.doc_type)]
          },
      }
  
      if pre_filter is not None:
          body["query"]["bool"]["filter"] = pre_filter
  
      res = self.es.search(
          index=self.index,
          body=body,
          size=self.size,
          timeout=self.timeout,
      )["hits"]["hits"]
  
      sigs = np.array(
          [x["_source"][self.doc_type]["signature"] for x in res]
      )
  
      if sigs.size == 0:
          return []
  
      dists = normalized_distance(sigs, np.array(signature))
  
      formatted_res = [
          {
              "id": x["_id"],
              "score": x["_score"],
              "metadata": x["_source"][self.doc_type].get("metadata"),
              "path": x["_source"][self.doc_type].get(
                  "url", x["_source"][self.doc_type].get("path")
              ),
          }
          for x in res
      ]
  
      for i, row in enumerate(formatted_res):
          row["dist"] = dists[i]
      formatted_res = filter(
          lambda y: y["dist"] < self.distance_cutoff, formatted_res
      )
  
      return formatted_res
  
file_path: image-match/image_match/elasticsearch_driver.py
imports: from .signature_database_base import SignatureDatabaseBase
  from .signature_database_base import normalized_distance
  from datetime import datetime
  import numpy
  from collections import deque
label_desc: Use image node_id 2 for calling the SignatureES obj's underlying member method code with example usage: obj.search_single_record(rec, pre_filter) and returns: formatted_res, list