opensearch-project / opensearch-js

Node.js Client for OpenSearch
https://opensearch.org/docs/latest/clients/javascript/
Apache License 2.0
186 stars 121 forks source link

[BUG] `createPit` client method is throwing `ResponseError: parse_exception: [parse_exception] Reason: request body is required` #746

Closed toyaokeke closed 5 months ago

toyaokeke commented 5 months ago

What is the bug?

the createPit method is throwing different errors, even though I am following the expected specifications from the opensearch user guide

I've also looked the source code for this method

How can one reproduce the bug?

sample TS file

import { Client } from '@opensearch-project/opensearch';

const INDEX_NAME = 'tests_func';

const esClient = new Client({
    node: `http://test_func_elastic:9200`,
    maxRetries: 1,
    requestTimeout: 60000,
});
await esClient.indices.create({ index: INDEX_NAME });
await esClient.createPit({ index: INDEX_NAME, keep_alive: '10m' });

What is the expected behavior?

expect the createPit method to create a PIT using my input params

What is your host/environment?

OS: macOs Sonoma 14.2.1 Running a containerized application (see the Dockerfile in the additional context) Docker version 20.10.22 Opensearch image 2.11.1 from AWS Public ECR

Do you have any screenshots?

If I remove body which is not a param in the SDK, I get this error image

if I remove keep_alive which is required I get this error image

If I add keep_alive and body (and expand_wilcards, which is also a valid parameter), I get this error image

Do you have any additional context?

Dockerfile

FROM public.ecr.aws/opensearchproject/opensearch:2.11.1
RUN /usr/share/opensearch/bin/opensearch-plugin remove opensearch-security && \
    /usr/share/opensearch/bin/opensearch-plugin install --batch analysis-kuromoji && \
    /usr/share/opensearch/bin/opensearch-plugin install --batch analysis-smartcn && \
    /usr/share/opensearch/bin/opensearch-plugin install --batch analysis-nori
# Openserach docker setup can be followed in these links
# https://opensearch.org/docs/latest/install-and-configure/install-opensearch/docker/
# https://opensearch.org/docs/latest/install-and-configure/install-opensearch/index/#important-settings
ENV cluster.name=docker-msproduct-cluster \
    network.host=0.0.0.0 \
    node.name=ms-product-elasticsearch \
    # Memory lock check.
    # see: https://www.elastic.co/guide/en/elasticsearch/reference/master/_memory_lock_check.html
    bootstrap.memory_lock=true \
    discovery.type=single-node \
    # helps functional tests not fail randomly due to low available disk space
    cluster.routing.allocation.disk.threshold_enabled=true \
    cluster.routing.allocation.disk.watermark.low=500mb \
    cluster.routing.allocation.disk.watermark.high=300mb \
    cluster.routing.allocation.disk.watermark.flood_stage=200mb \
    action.auto_create_index=false \
    path.repo=backup

package.json (simplified)

{
    "dependencies": {
        "@opensearch-project/opensearch": "^2.6.0"
    },
    "engines": {
        "node": ">= 20.8.0",
        "npm": ">= 10.1.0"
    }
}
nhtruong commented 5 months ago

I don't get that error and could create a PIT just fine:

cd .ci/opensearch
export OPENSEARCH_VERSION=2.11.0
docker compose up -d
const { Client } = require('@opensearch-project/opensearch');
const client = new Client({node: 'http://localhost:9200'});

const start = async () => {
const movies = 'movies';
await client.indices.create({ index: movies });
console.log(await client.createPit({ index: movies, keep_alive: '10m' }));
{
  body: {
    pit_id: 's4GCQQEGbW92aWVzFjFXeHIwZklXVDktNTRxN3pHajA3YkEAFl9rVFRKTWlvUkFxSUxHQnpWYUdwWEEAAAAAAAAAAAIWT3dscTBuN09SazItMm84TEJ4NXNvdwEWMVd4cjBmSVdUOS01NHE3ekdqMDdiQQAA',
    _shards: { total: 1, successful: 1, skipped: 0, failed: 0 },
    creation_time: 1712796391467
  },
  statusCode: 200,
  headers: {
    'content-type': 'application/json; charset=UTF-8',
    'content-length': '259'
  },
  meta: {
    context: null,
    request: { params: [Object], options: {}, id: 7 },
    name: 'opensearch-js',
    connection: {
      url: 'http://localhost:9200/',
      id: 'http://localhost:9200/',
      headers: {},
      deadCount: 0,
      resurrectTimeout: 0,
      _openRequests: 0,
      status: 'alive',
      roles: [Object]
    },
    attempts: 0,
    aborted: false
  }
}
toyaokeke commented 5 months ago

closing this issue, I managed to resolve the issue

dblock commented 5 months ago

@toyaokeke What was your issue (for the next person)?

toyaokeke commented 5 months ago

it seems like I may have been using an incorrect Dockerfile in my application. The Dockerfile iI shared was using Opensearch 2.11, but in my local tests I seemed to have been mistakenly using Elasticsearch 7.9, which does not support point in time