The msearch request must be terminated by a newline [\n]


I’m doing a Multi-search as per the documentation at

The multi-search query works fine in the Dev Tools dashboard, but when I copy & paste the query into my nodejs app, I get an issue that the msearch has to be terminated by a newline [\n]

I’ve tried to use a litteral string [``] to paste the query dsl into, but I still get the newline [\n] error.

I used os.EOL with no luck (thinking windows is causing the issue)
I used plain \n also with no luck.

The opensearch requests are being sent as a POST with the query in the body. Somehow, at the end of the body it is not recognizing the end of line. I’ve added this end of line everywhere and I still hvae the problem.

I am hoping someone has encounted this before.

Many thanks,

the answer…

I added my ‘end of line’ after I encoded my query:

helpers.textEncoder(_msearch) + os.EOL;

If you add the EOL at the end of the query itself, it doesn’t work.
In my case, I’m sending an https request and writing() the query/body.

Add the EOL after encoding the body/query, worked for me.

Hope this helps!


Glad you were able to get it working @DanielG - and we appreciate you coming back to post the answer, I’m sure others will also find this valuable!

Thanks Kris! I’m trying to find a consultant to help with some of the more challenging queries and to check my work, overall. Can’t seem to find any.

I hope more people will come here to help build this forum with lots of examples.


Hello @DanielG - one that comes to mind is OpenSource Connections. We also have a number of fantastic Partners who offer different services - I’d recommend looking through the Partners page to see who may be able to offer the service you’re looking for.

Hope this helps!

1 Like

Hi Kris,

Thanks for getting back to me and sorry for the delay.

We’re mainly interested in finding an expert in OpenSearch to help us out when we get stuck. As a developer myself, I would rather learn and build what I need instead of differing to a 3rd party service. :wink:

I’ve made more progress on my autosearch project. There’s a good description of how I’m doing my queries, here: Creating an Autocomplete Using Docs

Many thanks again for your time!


1 Like