Sending newlines with the IDE http client
Answered
Trying to test out some Elasticsearch batch requests, but Elasticvsearch being Elasticsearch has some funky syntax rules. They use a Content type called `application/x-ndjson` which is a newline delimited json format.
It wants something like this in curl format
curl -H "Content-Type: application/x-ndjson" -H "Accept: application/json" -XGET http://localhost:9200/_msearch -d '
{ "index": "docs_pages2" }
{ "query": { "dis_max": { "queries": [ { "nested": { "path": "versions", "query": { "match": { "versions.page_content": "Test Search" }}}}]}}}
'
The problem is that when I create this in the IDE's http client like this
GET http://localhost:9200/_msearch
Content-Type: application/x-ndjson
Accept: application/json
{ "index": "docs_pages2" }
{ "query": { "dis_max": { "queries": [ { "nested": { "path": "versions", "query": { "match": { "versions.page_content": "Test Search" }}}}]}}}
###
Elasticsearch then freaks out at me
HTTP/1.1 400 Bad Request
content-type: application/json; charset=UTF-8
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "The msearch request must be terminated by a newline [\n]"
}
],
"type": "illegal_argument_exception",
"reason": "The msearch request must be terminated by a newline [\n]"
},
"status": 400
}
I've tried
GET http://localhost:9200/_msearch
Content-Type: application/x-ndjson
Accept: application/json
{ "index": "docs_pages2" }\n
{ "query": { "dis_max": { "queries": [ { "nested": { "path": "versions", "query": { "match": { "versions.page_content": "Test Search" }}}}]}}}\n
\n
###
But I get the same issue.
It appears that when the IDE sends the payload, it's stripping the newlines
Is there anything I can do to deal with this?
IntelliJ IDEA Ultimate 2019.1
Please sign in to leave a comment.
Looks like https://youtrack.jetbrains.com/issue/WI-29754 (https://youtrack.jetbrains.com/issue/WI-40478 was closed as a duplicate of this one).
Thank you @Serge!