Skip to content

Commit

Permalink
Test/opensearch (#594)
Browse files Browse the repository at this point in the history
* test: testing opensearch

* ci: disable ssl

* Set package version

* support opensearch 2.x

---------

Co-authored-by: Vinicius Maciel <[email protected]>
Co-authored-by: Lucas Miranda <[email protected]>
Co-authored-by: Lucas Oliveira <[email protected]>
  • Loading branch information
4 people authored Feb 22, 2023
1 parent 218ea73 commit b17a502
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 40 deletions.
3 changes: 2 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
40 changes: 20 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/es-connector/aws.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/es-connector/index.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -45,7 +45,6 @@ export class SearchEngine<E, D extends Document> implements Provider<D> {
const esConfig = {
alias: `${actualPrefix}${domain}`,
index: `${actualPrefix}${domain}_index`,
dtype: "_doc",
settings: settings || {},
mappings: mappings || {},
};
Expand Down
5 changes: 1 addition & 4 deletions src/migration/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Client } from "@elastic/elasticsearch";
import { Client } from "@opensearch-project/opensearch";
import {
Settings,
GetSettingsResponse,
Expand Down Expand Up @@ -77,7 +77,6 @@ export class IndexManager {
public async createIndex(name: string = this.esConfig.index): Promise<void> {
await this.esClient.indices.create({
index: name,
include_type_name: false,
body: {
settings: this.esConfig.settings,
mappings: this.esConfig.mappings,
Expand Down Expand Up @@ -144,7 +143,6 @@ export class IndexManager {
},
} = await this.esClient.indices.getMapping<GetMappingsResponse>({
index,
include_type_name: false,
});
return mappings;
}
Expand All @@ -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({
Expand Down
10 changes: 5 additions & 5 deletions src/service.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -20,7 +24,6 @@ export interface Document {
export interface Config {
alias: string;
index: string;
dtype: string;
mappings: Mappings;
settings: Settings;
}
Expand Down Expand Up @@ -179,7 +182,6 @@ export class SearchService<D extends Document> implements Provider<D> {
await this.esClient.delete({
id: `${docId}`,
index: this.esConfig.alias,
type: this.esConfig.dtype,
routing,
refresh,
} as RequestParams.Delete);
Expand Down Expand Up @@ -264,7 +266,6 @@ export class SearchService<D extends Document> implements Provider<D> {
const response: ApiResponse<SearchResponse<D>> =
await this.esClient.search({
index: this.esConfig.alias,
type: this.esConfig.dtype,
body: searchBody,
from: window.from,
size: window.size,
Expand All @@ -285,7 +286,6 @@ export class SearchService<D extends Document> implements Provider<D> {
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;
Expand Down
2 changes: 1 addition & 1 deletion src/service.unit.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 4 additions & 2 deletions src/test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Client } from "@elastic/elasticsearch";
import { Client } from "@opensearch-project/opensearch";
import type { Logger } from "winston";
import { random } from "faker";

Expand All @@ -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 => {
Expand All @@ -28,7 +31,6 @@ export function getRandomConfig(): Config {
return {
index: getRandomSnakeCase(),
alias: getRandomSnakeCase(),
dtype: "_doc",
settings: {
number_of_shards: "1",
number_of_replicas: "1",
Expand Down
2 changes: 1 addition & 1 deletion test/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit b17a502

Please sign in to comment.