Skip to content

Commit

Permalink
Elasticsearch / API / Allow ndjson for _msearch endpoint (#8434)
Browse files Browse the repository at this point in the history
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 <fx.prunayre@gmail.com>
  • Loading branch information
geonetworkbuild and fxprunayre authored Oct 15, 2024
1 parent a47529c commit ae52739
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions services/src/main/java/org/fao/geonet/api/es/EsHTTPProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ae52739

Please sign in to comment.