Skip to content

Commit

Permalink
CMR-9443: Reduce size of Elasticsearch query return on some calls wit…
Browse files Browse the repository at this point in the history
…h unlimited page size (#2168)

* Removing source from some cwic and opensearch ES searchs

* Added a unit test

* add newline

* kondo changes
  • Loading branch information
TylerHeald1 committed Aug 30, 2024
1 parent 37a1fbd commit a518cfb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
5 changes: 3 additions & 2 deletions elastic-utils-lib/src/cmr/elastic_utils/search/es_index.clj
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
highlights
scroll
scroll-id
search-after]} query
search-after
remove-source]} query
scroll-timeout (when scroll (es-config/elastic-scroll-timeout))
search-type (if scroll
(es-config/elastic-scroll-search-type)
Expand All @@ -100,7 +101,7 @@
:sort sort-params
:size page-size
:from offset
:_source fields
:_source (if (nil? remove-source) fields false)
:aggs aggregations
:scroll scroll-timeout
:scroll-id scroll-id
Expand Down
29 changes: 29 additions & 0 deletions elastic-utils-lib/test/cmr/elastic_utils/test/es_index.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
(ns cmr.elastic-utils.test.es-index
"Tests for the cmr.elastic-utils.search.es-index namespace"
(:require
[clojure.test :refer [deftest is testing]]
[cmr.elastic-utils.search.es-index :as es-index]
[cmr.common.services.search.query-model :as qm]
[cmr.elastic-utils.search.es-group-query-conditions :as gc]))

(deftest test-query->execution-params
(let [query->execution-params #'es-index/query->execution-params
condition (gc/or-conds (map #(qm/string-conditions :consortiums [%])
["CWIC" "FEDEO" "GEOSS" "CEOS" "EOSDIS"]))]
(testing "query include remove-source"
(let [query (qm/query {:concept-type :collection
:result-format :xml
:condition condition
:page-size :unlimited
:remove-source true})
execution-params (query->execution-params query)]
(is (= false
(:_source execution-params)))))
(testing "query doesn't include remove-source"
(let [query (qm/query {:concept-type :collection
:result-format :xml
:condition condition
:page-size :unlimited})
execution-params (query->execution-params query)]
(is (not (= false
(:_source execution-params))))))))
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,26 @@

(defn get-cwic-collections
"Returns the collection granule count by searching elasticsearch by aggregation"
[context provider-ids]
[context _provider-ids]
(let [condition (qm/string-conditions :consortiums ["CWIC"])
query (qm/query {:concept-type :collection
:condition condition
:page-size :unlimited})
:page-size :unlimited
:remove-source true})
results (common-esi/execute-query context query)]
(into {}
(for [coll-id (map :_id (get-in results [:hits :hits]))]
[coll-id 1]))))

(defn get-opensearch-collections
"Returns the collection granule count by searching elasticsearch by aggregation"
[context provider-ids]
[context _provider-ids]
(let [condition (gc/or-conds (map #(qm/string-conditions :consortiums [%])
(common-config/opensearch-consortiums)))
query (qm/query {:concept-type :collection
:condition condition
:page-size :unlimited})
:page-size :unlimited
:remove-source true})
results (common-esi/execute-query context query)]
(into {}
(for [coll-id (map :_id (get-in results [:hits :hits]))]
Expand Down Expand Up @@ -141,11 +143,11 @@
(get-opensearch-collections context nil)))))))

(defjob RefreshHasGranulesOrCwicMapJob
[ctx system]
[_ctx system]
(refresh-has-granules-or-cwic-map {:system system}))

(defjob RefreshHasGranulesOrOpenSearchMapJob
[ctx system]
[_ctx system]
(refresh-has-granules-or-opensearch-map {:system system}))

(defn refresh-has-granules-or-cwic-map-job
Expand Down

0 comments on commit a518cfb

Please sign in to comment.