Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion elastic-utils-lib/src/cmr/elastic_utils/search/es_index.clj
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@
:payload-too-large
"The search is creating more buckets than allowed by CMR. Please narrow your search."))

(when (re-find #"maxClauseCount is set to 1024" body)
(when (and (= 400 (:status (ex-data e)))
(re-find #"(?i)(?:maxClauseCount is set to [0-9]+|too many clauses)" body))
(errors/throw-service-error
:payload-too-large
"The search is creating more clauses than allowed by CMR. Please narrow your search."))
Expand Down
44 changes: 44 additions & 0 deletions elastic-utils-lib/test/cmr/elastic_utils/test/es_index.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,53 @@
(:require
[clojure.test :refer [deftest is testing]]
[cmr.common.services.search.query-model :as qm]
[cmr.elastic-utils.es-helper :as es-helper]
[cmr.elastic-utils.search.es-group-query-conditions :as gc]
[cmr.elastic-utils.search.es-index :as es-index]))

(def clause-limit-message
"The search is creating more clauses than allowed by CMR. Please narrow your search.")

(defn- send-query-with-es-error
[status body]
(with-redefs [es-index/context->conn (constantly nil)
es-helper/search (fn [& _]
(throw (ex-info "Elasticsearch request failed"
{:status status
:body body})))]
(#'es-index/do-send-with-retry
{}
{:index-name "test-index" :type-name "collection"}
{}
1)))

(deftest clause-limit-errors-are-payload-too-large
(doseq [[description body]
[["Elasticsearch 7 default clause limit error"
"maxClauseCount is set to 1024"]
["Elasticsearch 7 configured clause limit error"
"maxClauseCount is set to 4096"]
["Elasticsearch 8 clause limit error"
(str "{\"error\":{\"root_cause\":[{\"type\":\"illegal_argument_exception\","
"\"reason\":\"Query rewrite failed: too many clauses\"}]},\"status\":400}")]]]
(testing description
(let [exception (try
(send-query-with-es-error 400 body)
nil
(catch clojure.lang.ExceptionInfo e
e))]
(is (= :payload-too-large (:type (ex-data exception))))
(is (= [clause-limit-message] (:errors (ex-data exception))))))))

(deftest clause-limit-errors-require-bad-request-status
(let [exception (try
(send-query-with-es-error 500 "Query rewrite failed: too many clauses")
nil
(catch clojure.lang.ExceptionInfo e
e))]
(is (nil? (:type (ex-data exception))))
(is (= 500 (:status (ex-data (ex-cause exception)))))))

(deftest test-query->execution-params
(let [query->execution-params #'es-index/query->execution-params
condition (gc/or-conds (map #(qm/string-conditions :consortiums [%])
Expand Down
Loading