|
22 | 22 | (defmulti concept-type->index-info |
23 | 23 | "Returns index info based on input concept type. The map should contain a :type-name key along |
24 | 24 | with an :index-name key. :index-name can refer to a single index or a comma separated string of |
25 | | - multiple index names." |
| 25 | + multiple index names. |
| 26 | + All index name strings in index-name are expected to be the same type as :type-name." |
26 | 27 | (fn [_context concept-type _query] |
27 | 28 | concept-type)) |
28 | 29 |
|
| 30 | +;; TODO 10636 -- why are these defmethods here and in search app and duplicated in access-control?...need to consolidate this |
29 | 31 | (defmethod concept-type->index-info :collection |
30 | 32 | [_context _ query] |
31 | 33 | {:index-name (if (:all-revisions? query) |
|
61 | 63 | in a system using the :search-index key." |
62 | 64 | [context es-cluster-name] |
63 | 65 | (cond |
64 | | - (= es-cluster-name cmr.elastic-utils.config/non-gran-elastic-name) (get-in context [:system :non-gran-search-index]) |
65 | | - (= es-cluster-name cmr.elastic-utils.config/gran-elastic-name) (get-in context [:system :gran-search-index]) |
66 | | - :else (throw (Exception. (str "expected specific elastic name but got " es-cluster-name " instead."))))) |
| 66 | + (= es-cluster-name cmr.elastic-utils.config/non-gran-elastic-name) (get-in context [:system :non-gran-search-index]) |
| 67 | + (= es-cluster-name cmr.elastic-utils.config/gran-elastic-name) (get-in context [:system :gran-search-index]) |
| 68 | + :else (throw (Exception. (str "expected specific elastic name but got " es-cluster-name " instead."))))) |
67 | 69 |
|
68 | 70 | (defn context->conn |
69 | 71 | "Returns the connection given a context. This assumes that the search index is always located in |
|
153 | 155 | (catch ExceptionInfo e |
154 | 156 | (handle-es-exception e scroll-id)))) |
155 | 157 |
|
| 158 | +;; TODO 10636 FIX THIS |
156 | 159 | ;; TODO 10636 this is hardcoded to index name...could it be better? Will these rules always be true? |
157 | 160 | ;; TODO unit test this -- need a sys test as well, so that if any index is created or found, we will auto warn that something could break with this |
158 | 161 | (defn get-es-cluster-name-from-index-name |
159 | 162 | "Returns the Elasticsearch cluster name based on the index name." |
160 | 163 | [index-name] |
| 164 | + ;; NOTE: expecting index-name to represent only one index-name as a string |
| 165 | + ;(println "10636- INSIDE get-es-cluster-from-index-name. Given index-name = " index-name) |
161 | 166 | (let [gran-cluster cmr.elastic-utils.config/gran-elastic-name |
162 | 167 | non-gran-cluster cmr.elastic-utils.config/non-gran-elastic-name |
163 | 168 | gran-index-set-name (str gran-cluster "-index-sets") |
|
170 | 175 | (or (string/starts-with? index-name "1_c") |
171 | 176 | (gran-specific-indices index-name) |
172 | 177 | (= index-name gran-index-set-name)))] |
173 | | - |
174 | 178 | (if uses-gran-cluster? |
175 | 179 | gran-cluster |
176 | 180 | non-gran-cluster))) |
177 | 181 |
|
| 182 | +(defn get-es-cluster-name-by-index-info-type |
| 183 | + [index-info] |
| 184 | + (if (= (:type index-info) "granule") |
| 185 | + cmr.elastic-utils.config/gran-elastic-name |
| 186 | + cmr.elastic-utils.config/non-gran-elastic-name)) |
| 187 | + |
178 | 188 | (defn- do-send-with-retry |
179 | 189 | "Sends a query to ES, either normal or using a scroll query." |
180 | 190 | [context index-info query max-retries] |
181 | | - ;; example index-info is {:index-name collection_search_alias, :type-name collection} |
| 191 | + ;; example index-info is {:index-name collection_search_alias, :type-name collection} OR {:index-name 1_c*,1_small_collections,-1_collections*, :type-name granule} |
182 | 192 | ;; will index-info always be one element or an array? |
183 | 193 | ;(println "INSIDE do-send-with-retry with index info = " index-info " and query = " query) |
184 | 194 | ;; index info = {:index-name , :type-name granule} |
185 | 195 | ;; query = {:search_type query_then_fetch, :size 10, :from 0, :timeout 170s, :version true, :query {:bool {:must {:match_all {}}, :filter {:bool {:must ({:term {:collection-concept-id-doc-values C1200000001-JM_PROV1}} {:term {:concept-id G1200000002-JM_PROV1}})}}}}, :_source (:concept-id :revision-id :native-id-stored :provider-id-doc-values :metadata-format :revision-date-stored-doc-values :collection-concept-id-doc-values), :sort ({:provider-id-lowercase-doc-values {:order :asc}} {:start-date-doc-values {:order :asc}} {:concept-seq-id-long {:order asc}})} |
186 | | - (info "10636- es cluster we are using = " (get-es-cluster-name-from-index-name (:index-name index-info))) |
| 196 | + (println "10636- INSIDE do-send-with-retry with index-info = " index-info ". Determined the es cluster is = " (get-es-cluster-name-by-index-info-type index-info)) |
187 | 197 | (try |
188 | 198 | (if (pos? max-retries) |
189 | 199 | (if-let [scroll-id (:scroll-id query)] |
190 | 200 | (scroll-search context scroll-id) |
191 | 201 | (es-helper/search |
192 | | - (context->conn context (get-es-cluster-name-from-index-name (:index-name index-info))) |
193 | | - (:index-name index-info) |
194 | | - [(:type-name index-info)] |
195 | | - query)) |
| 202 | + (context->conn context (get-es-cluster-name-by-index-info-type index-info)) |
| 203 | + (:index-name index-info) |
| 204 | + [(:type-name index-info)] |
| 205 | + query)) |
196 | 206 | (errors/throw-service-error :service-unavailable "Exhausted retries to execute ES query")) |
197 | 207 |
|
198 | 208 | (catch UnknownHostException _e |
|
284 | 294 | (set/rename-keys {:search-after :search_after}) |
285 | 295 | util/remove-nil-keys)] |
286 | 296 | (debug "Executing against indexes [" (:index-name index-info) "] the elastic query:" |
287 | | - (pr-str elastic-query) |
288 | | - "with sort" (pr-str sort-params) |
289 | | - "with aggregations" (pr-str aggregations) |
290 | | - "and highlights" (pr-str highlights)) |
| 297 | + (pr-str elastic-query) |
| 298 | + "with sort" (pr-str sort-params) |
| 299 | + "with aggregations" (pr-str aggregations) |
| 300 | + "and highlights" (pr-str highlights)) |
291 | 301 | (when-let [scroll-id (:scroll-id query-map)] |
292 | 302 | (debug "Using scroll-id" scroll-id)) |
293 | 303 | (when-let [search-after (:search_after query-map)] |
|
0 commit comments