diff --git a/docker-compose.yaml b/docker-compose.yaml index 0401f8e..dc70848 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -2,9 +2,10 @@ version: "3.8" services: elasticsearch: - image: docker.elastic.co/elasticsearch/elasticsearch:7.9.1 + image: opensearchproject/opensearch:2.3.0 environment: - "discovery.type=single-node" + - "DISABLE_SECURITY_PLUGIN=true" - "ES_JAVA_OPTS=-Xms256m -Xmx256m" ports: - 9200:9200 diff --git a/package-lock.json b/package-lock.json index 5a90f0f..7b7f3bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "searchops", - "version": "0.3.1", + "version": "0.3.3", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -436,17 +436,6 @@ "kuler": "^2.0.0" } }, - "@elastic/elasticsearch": { - "version": "7.13.0", - "resolved": "https://registry.npmjs.org/@elastic/elasticsearch/-/elasticsearch-7.13.0.tgz", - "integrity": "sha512-WgwLWo2p9P2tdqzBGX9fHeG8p5IOTXprXNTECQG2mJ7z9n93N5AFBJpEw4d35tWWeCWi9jI13A2wzQZH7XZ/xw==", - "requires": { - "debug": "^4.3.1", - "hpagent": "^0.1.1", - "ms": "^2.1.3", - "secure-json-parse": "^2.4.0" - } - }, "@emotion/hash": { "version": "0.8.0", "resolved": "https://registry.npmjs.org/@emotion/hash/-/hash-0.8.0.tgz", @@ -1208,6 +1197,18 @@ "fastq": "^1.6.0" } }, + "@opensearch-project/opensearch": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@opensearch-project/opensearch/-/opensearch-2.2.0.tgz", + "integrity": "sha512-E0f2Hooruz9y+17AF69oyyruikVMAEr1TxcQBNEQV4aQnI3o0+6CjqZS+t94SCZdWRTuN7HjIIVGbaYCJDpxgA==", + "requires": { + "aws4": "^1.11.0", + "debug": "^4.3.1", + "hpagent": "^1.2.0", + "ms": "^2.1.3", + "secure-json-parse": "^2.4.0" + } + }, "@opentelemetry/api": { "version": "0.14.0", "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-0.14.0.tgz", @@ -1915,8 +1916,7 @@ "aws4": { "version": "1.11.0", "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.11.0.tgz", - "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==", - "dev": true + "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==" }, "babel-jest": { "version": "26.6.3", @@ -4879,9 +4879,9 @@ "dev": true }, "hpagent": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/hpagent/-/hpagent-0.1.2.tgz", - "integrity": "sha512-ePqFXHtSQWAFXYmj+JtOTHr84iNrII4/QRlAAPPE+zqnKy4xJo7Ie1Y4kC7AdB+LxLxSTTzBMASsEcy0q8YyvQ==" + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/hpagent/-/hpagent-1.2.0.tgz", + "integrity": "sha512-A91dYTeIB6NoXG+PxTQpCCDDnfHsW9kc06Lvpu1TEe9gnd6ZFeiBoRO9JvzEv6xK7EX97/dUE8g/vBMTqTS3CA==" }, "html-encoding-sniffer": { "version": "2.0.1", @@ -8678,9 +8678,9 @@ } }, "secure-json-parse": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/secure-json-parse/-/secure-json-parse-2.4.0.tgz", - "integrity": "sha512-Q5Z/97nbON5t/L/sH6mY2EacfjVGwrCcSi5D3btRO2GZ8pf1K1UN7Z9H5J57hjVU2Qzxr1xO+FmBhOvEkzCMmg==" + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/secure-json-parse/-/secure-json-parse-2.7.0.tgz", + "integrity": "sha512-6aU+Rwsezw7VR8/nyvKTx8QpWH9FrcYiXXlqC4z5d5XQBDRqtbfsRjnwGyqbi3gddNtWHuEk9OANUotL26qKUw==" }, "semver": { "version": "7.3.4", diff --git a/package.json b/package.json index a1dc511..79ab411 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "searchops", - "version": "0.3.2", + "version": "0.3.3", "description": "Base operation files for search service", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -30,7 +30,7 @@ }, "homepage": "https://github.com/gupy-io/searchops#readme", "dependencies": { - "@elastic/elasticsearch": "7.13.0", + "@opensearch-project/opensearch": "^2.2.0", "ajv": "^7.1.1", "aws-sdk": "^2.847.0", "fast-json-stable-stringify": "^2.1.0" diff --git a/src/es-connector/aws.ts b/src/es-connector/aws.ts index ffef556..46db958 100644 --- a/src/es-connector/aws.ts +++ b/src/es-connector/aws.ts @@ -1,5 +1,5 @@ import { Readable } from "stream"; -import { Connection as UnsignedConnection } from "@elastic/elasticsearch"; +import { Connection as UnsignedConnection } from "@opensearch-project/opensearch"; import * as AWS from "aws-sdk"; import RequestSigner from "aws-sdk/lib/signers/v4"; import { ClientRequest, IncomingMessage } from "http"; diff --git a/src/es-connector/index.ts b/src/es-connector/index.ts index 8b1dd54..ed4dcee 100644 --- a/src/es-connector/index.ts +++ b/src/es-connector/index.ts @@ -1,5 +1,5 @@ import awsSdk from "aws-sdk"; -import { Client } from "@elastic/elasticsearch"; +import { Client } from "@opensearch-project/opensearch"; import type { WinstonLogger } from "../typings/winston"; import { AwsSignedConnection, UnsignedConnection } from "./aws"; diff --git a/src/index.ts b/src/index.ts index e4d9f7c..f58ad95 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import type { WinstonLogger } from "./typings/winston"; -import { Client, RequestParams } from "@elastic/elasticsearch"; +import { Client, RequestParams } from "@opensearch-project/opensearch"; import { Config, @@ -45,7 +45,6 @@ export class SearchEngine implements Provider { const esConfig = { alias: `${actualPrefix}${domain}`, index: `${actualPrefix}${domain}_index`, - dtype: "_doc", settings: settings || {}, mappings: mappings || {}, }; diff --git a/src/migration/index.ts b/src/migration/index.ts index f91c070..7fead50 100644 --- a/src/migration/index.ts +++ b/src/migration/index.ts @@ -1,4 +1,4 @@ -import { Client } from "@elastic/elasticsearch"; +import { Client } from "@opensearch-project/opensearch"; import { Settings, GetSettingsResponse, @@ -77,7 +77,6 @@ export class IndexManager { public async createIndex(name: string = this.esConfig.index): Promise { await this.esClient.indices.create({ index: name, - include_type_name: false, body: { settings: this.esConfig.settings, mappings: this.esConfig.mappings, @@ -144,7 +143,6 @@ export class IndexManager { }, } = await this.esClient.indices.getMapping({ index, - include_type_name: false, }); return mappings; } @@ -156,7 +154,6 @@ export class IndexManager { await this.esClient.indices.putMapping({ index, body: mappings, - include_type_name: false, }); if (this.triggerUpdate) { await this.esClient.updateByQuery({ diff --git a/src/service.ts b/src/service.ts index 788fc0b..cb2217b 100644 --- a/src/service.ts +++ b/src/service.ts @@ -1,5 +1,9 @@ import type { WinstonLogger } from "./typings/winston"; -import { Client, RequestParams, ApiResponse } from "@elastic/elasticsearch"; +import { + Client, + RequestParams, + ApiResponse, +} from "@opensearch-project/opensearch"; import * as AJV from "ajv"; import { Settings, @@ -20,7 +24,6 @@ export interface Document { export interface Config { alias: string; index: string; - dtype: string; mappings: Mappings; settings: Settings; } @@ -179,7 +182,6 @@ export class SearchService implements Provider { await this.esClient.delete({ id: `${docId}`, index: this.esConfig.alias, - type: this.esConfig.dtype, routing, refresh, } as RequestParams.Delete); @@ -264,7 +266,6 @@ export class SearchService implements Provider { const response: ApiResponse> = await this.esClient.search({ index: this.esConfig.alias, - type: this.esConfig.dtype, body: searchBody, from: window.from, size: window.size, @@ -285,7 +286,6 @@ export class SearchService implements Provider { try { const response = await this.esClient.count({ index: this.esConfig.alias, - type: this.esConfig.dtype, body, } as RequestParams.Count); return response.body.count as number; diff --git a/src/service.unit.test.ts b/src/service.unit.test.ts index 9b159af..2900f5f 100644 --- a/src/service.unit.test.ts +++ b/src/service.unit.test.ts @@ -1,6 +1,6 @@ import { jest, expect, describe, describe as context, it } from "@jest/globals"; import { createLogger } from "winston"; -import { Client } from "@elastic/elasticsearch"; +import { Client } from "@opensearch-project/opensearch"; import { SearchService, Config, diff --git a/src/test/utils.ts b/src/test/utils.ts index c2a1a8d..51db4af 100644 --- a/src/test/utils.ts +++ b/src/test/utils.ts @@ -1,4 +1,4 @@ -import { Client } from "@elastic/elasticsearch"; +import { Client } from "@opensearch-project/opensearch"; import type { Logger } from "winston"; import { random } from "faker"; @@ -14,6 +14,9 @@ export function getTestClient(logger?: Logger): Client { const elasticPort = process.env.ELASTIC_PORT ?? "9200"; const esClient: Client = new Client({ node: `http://${elasticHost}:${elasticPort}`, + ssl: { + rejectUnauthorized: false, + }, }); if (logger) { esClient.on("response", (error, result): void => { @@ -28,7 +31,6 @@ export function getRandomConfig(): Config { return { index: getRandomSnakeCase(), alias: getRandomSnakeCase(), - dtype: "_doc", settings: { number_of_shards: "1", number_of_replicas: "1", diff --git a/test/build/package.json b/test/build/package.json index 048eb24..c3e046f 100644 --- a/test/build/package.json +++ b/test/build/package.json @@ -5,7 +5,7 @@ "build": "rm -rf ../../node_modules && tsc --noEmit" }, "dependencies": { - "searchops": "file:../../searchops-0.3.2.tgz" + "searchops": "file:../../searchops-0.3.3.tgz" }, "devDependencies": { "@types/node": "^14.11.2",