                                     (map (fn [qp]
                                            (str/replace-first qp #"\]\[.*\]"
                                                               (format "][%s]" subfield))))
-                                    (select-keys query-params))]
-          ; matching-indexes (map keys matching-indexes)
-          ; matching-indexes (map (fn [ancestor])
-
-                                ; matching-indexes)
-                              ;  (map #(first (keys %))))
-          ; potential-qp-matches nil]
-          ; potential-qp-matches (when ancestors-found?
-          ;                        (->> ancestors-found
-          ;                             (filter #(= (count (first ancestors-to-match)) (count %)))))]
-
-                                      ; (map #(select-keys % [subfield]))
-                                      ; (into {})))]
-          ; potential-qp-matches (into {}
-          ;                            (map #(for [[k v] %
-          ;                                        :when (re-find (re-pattern subfield) k)]
-          ;                                    [k v])
-          ;                                 potential-qp-matches))]
-
-        ; (println "matching indexes are" matching-indexes)
+                                    (select-keys query-params))
+
+          ;; TODO change to multiple indexes
+          ; idx (some->> potential-qp-matches
+          ;              keys
+          ;              first
+          ;              (re-find #"\[\d+\]")
+          ;              second)
+          ; _ (println "IDX=" idx)
+          ; child-matches (when idx
+          ;                 (concat (for [[k v] applied-children-tuples]
+          ;                           [(format "%s[%s][%s]" base-field idx (csk/->snake_case_string k))
+          ;                            v])))
+          indexes (some->> potential-qp-matches
+                           keys
+                           (map #(re-find #"\[\d+\]" %))
+                           (map second)
+                           set)
+          _ (println "IDX=" indexes)
+          child-matches (mapcat
+                          (fn [idx]
+                            (concat (for [[k v] applied-children-tuples]
+                                      [(format "%s[%s][%s]" base-field idx (csk/->snake_case_string k))
+                                       v])))
+                          indexes)]
+        (println "Child matches are" child-matches)
+
         (println "potential-qp-matches are" potential-qp-matches)
-          ; exact-query-params (map #(str/replace-first field-name "[0]" (format "[%s]" %)) parent-indexes)
-          ; _ (println "Exact query params are" exact-query-params)]
-          ; potential-query-params (into {} (filter (fn [[k _]]
-          ;                                           (seq (filter #(= % k) exact-query-params)))
-          ;                                         query-params))
-          ; _ (when (= value "Level2-2") (println "Potential query params for" value ":" potential-query-params))
-          ; value-exists? (or (seq (get-keys-to-remove potential-query-params value))
-          ;                   (seq (get-keys-to-update potential-query-params value)))]
-      ; (println "Value exists is" value-exists?)
-          ;                                                      (format "[%d]" parent-indexes))]
-          ;             (println "Exact query-param is: " exact-query-param "and value is" value "and found existing query-param"
-          ;                      (get query-params exact-query-param))
-          ;             ; (throw "Failed")
-          ;             (filter (fn [[k _]] (= exact-query-param k)) query-params))
+
       (if ancestors-found?
         (println "Found all ancestors!! for" field-name "and" value)
         (println "Did not find ancestors" ancestors-to-match ancestors-found))

  value - the value to apply (or remove) for the given field-name."
  (:require [camel-snake-kebab.core :as csk]
            [ring.util.codec :as codec]
            [clojure.string :as str]))

(defn- set-and-options-for-param
  "If the provided field has more than one value applied in the query params, add in an options

   (let [[base-field subfield] (str/split field-name #"\[0\]")
         updated-params (reduce (partial process-removal-for-field-value-tuple base-field potential-qp-matches)
                                query-params
                                (conj applied-children-tuples [subfield value]))
         ;; TODO Remove any extraneous parameters
         updated-params (remove-duplicate-params updated-params base-field)]
     {:remove (generate-query-string base-url updated-params)})))

(defn create-link-for-hierarchical-field
  "Creates either a remove or an apply link based on whether this particular value is already
