Skip to content

Commit 78d766b

Browse files
authored
Merge pull request #2483 from nasa/CMR-11419
CMR-11419: fix error handling for ES8 query complexity limit
2 parents 856c6b5 + 43ff891 commit 78d766b

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

elastic-utils-lib/src/cmr/elastic_utils/search/es_index.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@
217217
:payload-too-large
218218
"The search is creating more buckets than allowed by CMR. Please narrow your search."))
219219

220-
(when (re-find #"maxClauseCount is set to 1024" body)
220+
(when (and (= 400 (:status (ex-data e)))
221+
(re-find #"(?i)(?:maxClauseCount is set to [0-9]+|too many clauses)" body))
221222
(errors/throw-service-error
222223
:payload-too-large
223224
"The search is creating more clauses than allowed by CMR. Please narrow your search."))

elastic-utils-lib/test/cmr/elastic_utils/test/es_index.clj

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,53 @@
33
(:require
44
[clojure.test :refer [deftest is testing]]
55
[cmr.common.services.search.query-model :as qm]
6+
[cmr.elastic-utils.es-helper :as es-helper]
67
[cmr.elastic-utils.search.es-group-query-conditions :as gc]
78
[cmr.elastic-utils.search.es-index :as es-index]))
89

10+
(def clause-limit-message
11+
"The search is creating more clauses than allowed by CMR. Please narrow your search.")
12+
13+
(defn- send-query-with-es-error
14+
[status body]
15+
(with-redefs [es-index/context->conn (constantly nil)
16+
es-helper/search (fn [& _]
17+
(throw (ex-info "Elasticsearch request failed"
18+
{:status status
19+
:body body})))]
20+
(#'es-index/do-send-with-retry
21+
{}
22+
{:index-name "test-index" :type-name "collection"}
23+
{}
24+
1)))
25+
26+
(deftest clause-limit-errors-are-payload-too-large
27+
(doseq [[description body]
28+
[["Elasticsearch 7 default clause limit error"
29+
"maxClauseCount is set to 1024"]
30+
["Elasticsearch 7 configured clause limit error"
31+
"maxClauseCount is set to 4096"]
32+
["Elasticsearch 8 clause limit error"
33+
(str "{\"error\":{\"root_cause\":[{\"type\":\"illegal_argument_exception\","
34+
"\"reason\":\"Query rewrite failed: too many clauses\"}]},\"status\":400}")]]]
35+
(testing description
36+
(let [exception (try
37+
(send-query-with-es-error 400 body)
38+
nil
39+
(catch clojure.lang.ExceptionInfo e
40+
e))]
41+
(is (= :payload-too-large (:type (ex-data exception))))
42+
(is (= [clause-limit-message] (:errors (ex-data exception))))))))
43+
44+
(deftest clause-limit-errors-require-bad-request-status
45+
(let [exception (try
46+
(send-query-with-es-error 500 "Query rewrite failed: too many clauses")
47+
nil
48+
(catch clojure.lang.ExceptionInfo e
49+
e))]
50+
(is (nil? (:type (ex-data exception))))
51+
(is (= 500 (:status (ex-data (ex-cause exception)))))))
52+
953
(deftest test-query->execution-params
1054
(let [query->execution-params #'es-index/query->execution-params
1155
condition (gc/or-conds (map #(qm/string-conditions :consortiums [%])

0 commit comments

Comments
 (0)