Skip to content

Commit

Permalink
Elasticsearch / API / Allow ndjson for _msearch endpoint
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'
  
```
  • Loading branch information
fxprunayre committed Oct 15, 2024
1 parent 9afd1bf commit eb1a2e9
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 @@ -330,11 +330,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 eb1a2e9

Please sign in to comment.