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

Multisearch examples and formatting #634

Open
hyprstack opened this issue Oct 18, 2023 · 4 comments
Open

Multisearch examples and formatting #634

hyprstack opened this issue Oct 18, 2023 · 4 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@hyprstack
Copy link

I am using the opensearchJs client to send requests. When looking through the docs there are no examples on how a multisearch query body should be structured in order to use the client correctly.

Does the user need to format the body such that each query needs to be on a single line as defined here or does the client do this formatting if given a normal array of json objects as seen in the example here using the Ruby api for elasticsearch?

Also, if each object needs to be on a single line, could this be achieved by simply doing a JSON.stringify on the object, as in:

[
  JSON.stringify({}),
  JSON.stringify({
      "from": 0,
      "limit": 5,
      "query": {
        "bool": {
          ...
        }
      }
    }
  )
]

i.e. do I need to format the body to

[
  {},
  {"from": 0, "limit": 5, "query": {"query": {"bool": {...}}}}
]

Or could I pass in

[
  {},
  {
    "from": 0,
    "limit": 5,
    "query": {
      "bool": {
        ...
      }
    }
  }
]
@nhtruong nhtruong added good first issue Good for newcomers and removed untriaged labels Nov 14, 2023
@tejeshreddy
Copy link
Contributor

@nhtruong can I take this issue up?

@nhtruong
Copy link
Collaborator

@tejeshreddy of course!

@tejeshreddy
Copy link
Contributor

@nhtruong just to check with you, the documentation is expected to be changed to clarify the above queries right?

@nhtruong
Copy link
Collaborator

nhtruong commented Nov 15, 2023

@hyprstack The body that the _msearch endpoint accepts is a string representation of NDJSON (newline deliminated JSON: A collection of JSON objects that are seperated by \n). You can manually do the serialization and turn your array of objects into said string OR you can just pass the array of objects as is to the client.msearch method. The client will detect that it's an array and perform the serialization for you.

@tejeshreddy You can add an entry in guides folder called msearch.md with working examples and instructions.

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

No branches or pull requests

3 participants