code: def convert(filters: Dict[str, Any]) -> Dict[str, Any]:
      """
      Convert a filter declared using the legacy style into the new style.
      This is mostly meant to ease migration from Haystack 1.x to 2.x for developers
      of Document Stores and Components that use filters.
  
      This function doesn't verify if `filters` are declared using the legacy style.
  
      Example usage:
      ```python
      legacy_filter = {
          "$and": {
              "type": {"$eq": "article"},
              "date": {"$gte": "2015-01-01", "$lt": "2021-01-01"},
              "rating": {"$gte": 3},
              "$or": {"genre": {"$in": ["economy", "politics"]}, "publisher": {"$eq": "nytimes"}},
          }
      }
      assert convert(legacy_filter) == {
          "operator": "AND",
          "conditions": [
              {"field": "type", "operator": "==", "value": "article"},
              {"field": "date", "operator": ">=", "value": "2015-01-01"},
              {"field": "date", "operator": "<", "value": "2021-01-01"},
              {"field": "rating", "operator": ">=", "value": 3},
              {
                  "operator": "OR",
                  "conditions": [
                      {"field": "genre", "operator": "in", "value": ["economy", "politics"]},
                      {"field": "publisher", "operator": "==", "value": "nytimes"},
                  ],
              },
          ],
      }
      ```
      """
      if not isinstance(filters, dict):
          msg = f"Can't convert filters from type '{type(filters)}'"
          raise ValueError(msg)
  
      converted = _internal_convert(filters)
      if "conditions" not in converted:
          # This is done to handle a corner case when filter is really simple like so:
          #   {"text": "A Foo Document 1"}
          # The root '$and' operator is implicit so the conversion doesn't handle
          # it and it must be added explicitly like so.
          # This only happens for simple filters like the one above.
          return {"operator": "AND", "conditions": [converted]}
      return converted
  
imports: from typing import List, Any, Union, Dict
  from dataclasses import fields
  from datetime import datetime
  import pandas
  from haystack.dataclasses import Document
  from haystack.errors import FilterError
label_desc: Use image node_id 15 for calling a global function with example usage: convert(filters) and returns: converted, dict