             [cmr.search.data.datetime-helper :as h]
             [cmr.common.services.errors :as errors]
             [cmr.search.data.messages :as m]
-            [cmr.search.data.keywords-to-elastic :as k2e]))
+            [cmr.search.data.keywords-to-elastic :as k2e]
+            [cmr.common.config :as cfg]))
+
+(def numeric-range-execution-mode (cfg/config-value-fn :numeric-range-execution-mode "index"))
+(def numeric-range-use-cache (cfg/config-value-fn "true" :numeric-range-use-cache #(= "true" %)))
 
 (def field-mappings
   "A map of fields in the query to the field name in elastic. Field names are excluded from this

  (condition->elastic
    [{:keys [field min-value max-value]} concept-type]
    (range-condition->elastic (query-field->elastic-field field concept-type)
                              min-value max-value "index"))

  cmr.search.models.query.NumericRangeIntersectionCondition
  (condition->elastic

(defn- range-condition->elastic
  "Convert a range condition to an elastic search condition. Execution
  should either by 'fielddata' or 'index'."
  ([field min-value max-value execution]
   (range-condition->elastic field min-value max-value execution true))
  ([field min-value max-value execution use-cache]
   (cond
     (and min-value max-value)
     {:range {field {:gte min-value :lte max-value}
              :execution execution
              :_cache use-cache}}

     min-value
     {:range {field {:gte min-value}
              :execution execution
              :_cache use-cache}}

     max-value
     {:range {field {:lte max-value}
              :execution execution
              :_cache use-cache}}

     :else
     (errors/internal-error! (m/nil-min-max-msg)))))

(extend-protocol ConditionToElastic
  cmr.search.models.query.ConditionGroup
