Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong content type: "application/json" #1360

Open
eliasbaixas opened this issue Apr 27, 2024 · 2 comments
Open

Wrong content type: "application/json" #1360

eliasbaixas opened this issue Apr 27, 2024 · 2 comments

Comments

@eliasbaixas
Copy link

The problem

I am proxying the searchkit requests through a Rails controller, but it breaks because Rails tries to parse the request.body as json (as the content-type: application/json suggests). But JSON.parse(request.raw_body) blows because the body is actually not proper json, its a concatenation of 2 or more json strings, which on itself is not proper json.

Environment

  • Searchkit version (or git revision) that exhibits the issue: 4.11.2
  • Last Searchkit version that did not exhibit the issue (if applicable):
  • Node.js version: 20.6.1
  • Typescript version:5.4.5
  • ElasticSearch/OpenSearch version: Opensearch 2.11.1

Details

from inspecting the requests and code, the request body sent is built from:

export const createElasticsearchQueryFromRequest = (requests: SearchRequest[]) => {

and the wrong content-type: application/json is sent from:

'content-type': 'application/json',

Code To Reproduce Issue

Just any searchkit request is technically invalid: if the content-type header is 'application/json' the request body shoud adhere to RFC 7159 and be a proper JSON string (not a newline concatenation).

One way to fix this would be to send application/x-ndjson as content-type.

@eliasbaixas
Copy link
Author

There are some examples of using curl to insert records to elasticsearch in the searchkit page, and they correctly use application/x-ndjson content-type:

https://www.searchkit.co/docs/getting-started/setup

@joemcelroy
Copy link
Member

yeh i think the fix here is that it needs to send as content-type application/x-ndjson. Will need to test this or happy to accept a PR for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants