From ae5273972d66db43e5c457cf1aa09b10eef5f814 Mon Sep 17 00:00:00 2001 From: GeoNetwork opensource <59019313+geonetworkbuild@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:21:49 +0200 Subject: [PATCH] Elasticsearch / API / Allow ndjson for _msearch endpoint (#8434) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some libraries/apps are using `_msearch` endpoint which can allow both `application/json` or `application/x-ndjson` content type. When ndjson is used, the API call is not forwarded to Elasticsearch ``` ERROR [geonetwork] - Content type 'application/x-ndjson' not supported ``` Cf. https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html eg. ``` curl -L 'https://apps.titellus.net/geonetwork/mapstore/api/search/records/_msearch?' \ -H 'accept: application/json' \ -H 'content-type: application/x-ndjson' \ --data-raw $'{"preference":"cardQuickFilter_2"}\n{"query":{"bool":{"must":[{"bool":{"must":[{"query_string":{"query":"+(resourceType:application) -(th_infraSIG.default:Reporting_INSPIRE) -(cl_status.key:obsolete)"}}]}}]}},"size":0,"_source":{"includes":["*"],"excludes":[]},"aggs":{"th_Themes_geoportail_wallon_hierarchy.default":{"terms":{"field":"th_Themes_geoportail_wallon_hierarchy.default","size":100,"order":{"_count":"desc"}}}}}\n' ``` Co-authored-by: François Prunayre --- .../main/java/org/fao/geonet/api/es/EsHTTPProxy.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/services/src/main/java/org/fao/geonet/api/es/EsHTTPProxy.java b/services/src/main/java/org/fao/geonet/api/es/EsHTTPProxy.java index b8ed0eb6376..ac2c10669d7 100644 --- a/services/src/main/java/org/fao/geonet/api/es/EsHTTPProxy.java +++ b/services/src/main/java/org/fao/geonet/api/es/EsHTTPProxy.java @@ -320,11 +320,15 @@ public void search( description = "The multi search API executes several searches from a single API request. See https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html for search parameters, and https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html Query DSL.") @RequestMapping(value = "/search/records/_msearch", method = RequestMethod.POST, - produces = MediaType.APPLICATION_JSON_VALUE, - consumes = MediaType.APPLICATION_JSON_VALUE) + produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_NDJSON_VALUE}, + consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_NDJSON_VALUE}) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Search results.", - content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(type = "string"))) + content = { + @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(type = "string")), + @Content(mediaType = MediaType.APPLICATION_NDJSON_VALUE, schema = @Schema(type = "string")) + } + ) }) @ResponseStatus(value = HttpStatus.OK) @ResponseBody