code: def _to_es_query(cls, query: BackendRecordsQuery) -> Dict[str, Any]:
      if query.ids:
          return filters.ids_filter(query.ids)
  
      query_text = filters.text_query(query.query_text)
      all_filters = filters.metadata(query.metadata)
      if query.has_annotation:
          all_filters.append(filters.exists_field("annotated_by"))
      if query.has_prediction:
          all_filters.append(filters.exists_field("predicted_by"))
  
      query_data = query.dict(
          exclude={
              "vector",
              "query_text",
              "metadata",
              "uncovered_by_rules",
              "has_annotation",
              "has_prediction",
          }
      )
      for key, value in query_data.items():
          if value is None:
              continue
          key_filter = None
          if isinstance(value, dict):
              value = getattr(
                  query, key
              )  # check the original field type
          if isinstance(value, list):
              key_filter = filters.terms_filter(key, value)
          elif isinstance(value, (str, Enum)):
              key_filter = filters.term_filter(key, value)
          elif isinstance(value, QueryRange):
              key_filter = filters.range_filter(
                  field=key,
                  value_from=value.range_from,
                  value_to=value.range_to,
              )
  
          else:
              cls._LOGGER.warning(
                  f"Cannot parse query value {value} for key {key}"
              )
          if key_filter:
              all_filters.append(key_filter)
  
      boolean_filter_query = filters.boolean_filter(
          must_query=query_text or filters.match_all(),
          filter_query=filters.boolean_filter(
              should_filters=all_filters,
              minimum_should_match=len(all_filters),
          )
          if all_filters
          else None,
          must_not_query=filters.boolean_filter(
              should_filters=[
                  filters.text_query(q)
                  for q in query.uncovered_by_rules
              ]
          )
          if hasattr(query, "uncovered_by_rules")
          and query.uncovered_by_rules
          else None,
      )
  
      return boolean_filter_query
  
imports: import logging
  import re
  from enum import Enum
  from typing import Any, Dict, List, Optional, Union
  from argilla.server.daos.backend.query_helpers import filters
  from argilla.server.daos.backend.search.model import BackendDatasetsQuery, BackendQuery, BackendRecordsQuery, BaseDatasetsQuery, QueryRange, SortableField, SortConfig
label_desc: Use image node_id 6 for calling the EsQueryBuilder obj's underlying member method code with example usage: obj._to_es_query(cls, query) and returns: boolean_filter_query, filters