             [clojurewerkz.elastisch.rest :as esr]
             [clojurewerkz.elastisch.rest.index :as esi]))
 
+(def ^:private token-document-null-value "NOBODY")
+
 ;; (esr/connect! "http://127.0.0.1:9200")
-
-(def mapping-types
-  {"doc" {:_all {:enabled false},
-          :properties
-          {:parent {:index "not_analyzed", :type "string", :store "yes"},
-           :tags {:index "not_analyzed",
-                  :type "string",
-                  :index_options "docs",
-                  :store true,
-                  :omit_norms true},
-           :lastmodified {:type "date", :store "yes"},
-           :content {:type "string", :store "yes"},
-           :title   {:type "string", :store "yes"},
-
-           :deny_token_document {:index "not_analyzed",
-                                 :type "string",
-                                 :store true,
-                                 :null_value "UNAUTHENTICATED"},
-           :allow_token_document {:index "not_analyzed",
-                                  :type "string",
-                                  :store true,
-                                  :null_value "NOBODY"}},
-          :_source {:enabled false}},
-   "dir" {:_all {:enabled false},
-          :properties
-          {:lastmodified {:type "date", :store "yes"},
-           :parent {:index "not_analyzed", :type "string", :store "yes"}},
-          :_source {:enabled false}}})
+(let [parent {:index "not_analyzed", :type "string", :store "yes"}
+      token {:index "not_analyzed",
+             :type "string",
+             :store true,
+             :null_value token-document-null-value}]
+  (def mapping-types
+    {"doc" {:_all {:enabled false},
+            :_source {:enabled false},
+            :properties
+            {:parent parent
+             :tags {:index "not_analyzed",
+                    :type "string",
+                    :index_options "docs",
+                    :store true,
+                    :omit_norms true},
+             :lastmodified {:type "date", :store "yes"},
+             :content {:type "string", :store "yes"},
+             :title   {:type "string", :store "yes"},
+             :deny_token_document token,
+             :allow_token_document token}},
+     "dir" {:_all {:enabled false},
+            :_source {:enabled false}
+            :properties
+            {:lastmodified {:type "date", :store "yes"},
+             :parent parent}}}))
 
 ;;; when sending around messages via rabbitmq we pass the lastmodified
 ;;; date as unix time (as integer). the field is called mtime while in

              :content (get-in body [:extract :tika-content :text])
              :title title
              :tags (get-tags-from-path directory)
              :allow_token_document (simple-perms true)
              :deny_token_document (simple-perms false)
              :lastmodified (mtime->lastmodified (get-in entry [:stat :mtime]))})))



             {:lastmodified (mtime->lastmodified (:mtime e))
              :parent parent-id})))

(let [default-value (list token-document-null-value)]
  (defn simplify-permissions-for-es
    [permissions]
    (let [allow->sids (misc/remap #(sort (set (map :sid %)))
                                  (group-by :allow permissions))]
      {:allow (allow->sids true default-value)
       :deny  (allow->sids false default-value)})))

(defn get-tags-from-path
  [s]
