|
7 | 7 |
|
8 | 8 | package org.elasticsearch.xpack.eql.execution.search; |
9 | 9 |
|
| 10 | +import org.elasticsearch.ElasticsearchStatusException; |
10 | 11 | import org.elasticsearch.action.ActionListener; |
11 | 12 | import org.elasticsearch.action.search.ClosePointInTimeRequest; |
12 | 13 | import org.elasticsearch.action.search.ClosePointInTimeResponse; |
13 | 14 | import org.elasticsearch.action.search.MultiSearchRequest; |
14 | 15 | import org.elasticsearch.action.search.MultiSearchResponse; |
15 | 16 | import org.elasticsearch.action.search.OpenPointInTimeRequest; |
| 17 | +import org.elasticsearch.action.search.OpenPointInTimeResponse; |
16 | 18 | import org.elasticsearch.action.search.SearchRequest; |
17 | 19 | import org.elasticsearch.action.search.SearchResponse; |
18 | 20 | import org.elasticsearch.action.search.TransportClosePointInTimeAction; |
@@ -140,10 +142,33 @@ private <Response> void openPIT(ActionListener<Response> listener, Runnable runn |
140 | 142 | .keepAlive(keepAlive) |
141 | 143 | .allowPartialSearchResults(allowPartialSearchResults); |
142 | 144 | request.indexFilter(filter); |
143 | | - client.execute(TransportOpenPointInTimeAction.TYPE, request, listener.delegateFailureAndWrap((l, r) -> { |
144 | | - pitId = r.getPointInTimeId(); |
145 | | - runnable.run(); |
146 | | - })); |
| 145 | + |
| 146 | + client.execute(TransportOpenPointInTimeAction.TYPE, request, new ActionListener<>() { |
| 147 | + @Override |
| 148 | + public void onResponse(OpenPointInTimeResponse r) { |
| 149 | + try { |
| 150 | + pitId = r.getPointInTimeId(); |
| 151 | + runnable.run(); |
| 152 | + } catch (Exception e) { |
| 153 | + onFailure(e); |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + @Override |
| 158 | + public void onFailure(Exception e) { |
| 159 | + if (allowPartialSearchResults |
| 160 | + && e instanceof ElasticsearchStatusException |
| 161 | + && e.getMessage() |
| 162 | + .contains("The [allow_partial_search_results] parameter cannot be used while the cluster is still upgrading.")) { |
| 163 | + // This is for pre-8.16 |
| 164 | + // We cannot use allow_partial_search_results during upgrades, so let's try without and hope to get no shard failures, |
| 165 | + // it's the best we can do, the query would fail anyway |
| 166 | + openPIT(listener, runnable, false); |
| 167 | + } else { |
| 168 | + listener.onFailure(e); |
| 169 | + } |
| 170 | + } |
| 171 | + }); |
147 | 172 | } |
148 | 173 |
|
149 | 174 | @Override |
|
0 commit comments