Update v8.x support

pull/6904/head
Jacob Beneski 2 years ago
parent f311505a26
commit 205a7c8c13

@ -15,7 +15,7 @@ props:
- '8.x' - '8.x'
- '7.x' - '7.x'
- '6.x' - '6.x'
default: '6.x' default: '7.x'
hosts: hosts:
type: String type: String
title: Host(s) title: Host(s)

@ -20,7 +20,7 @@ module.exports = {
WIKI.logger.info(`(SEARCH/ELASTICSEARCH) Initializing...`) WIKI.logger.info(`(SEARCH/ELASTICSEARCH) Initializing...`)
switch (this.config.apiVersion) { switch (this.config.apiVersion) {
case '8.x': case '8.x':
WIKI.logger.info(`Using ElasticSearch 8.X`) WIKI.logger.info(`Using ElasticSearch 8.X`) // TODO Remove this line
const { Client: Client8 } = require('elasticsearch8') const { Client: Client8 } = require('elasticsearch8')
this.client = new Client8({ this.client = new Client8({
nodes: this.config.hosts.split(',').map(_.trim), nodes: this.config.hosts.split(',').map(_.trim),
@ -65,6 +65,7 @@ module.exports = {
async createIndex() { async createIndex() {
try { try {
const indexExists = await this.client.indices.exists({ index: this.config.indexName }) const indexExists = await this.client.indices.exists({ index: this.config.indexName })
// 6.x / 7.x return indexExists.body, while 8.x only returns indexExists so we need uniqe conditionals
if ((!indexExists.body && this.config.apiVersion !== '8.x') || (!indexExists && this.config.apiVersion === '8.x')) { if ((!indexExists.body && this.config.apiVersion !== '8.x') || (!indexExists && this.config.apiVersion === '8.x')) {
WIKI.logger.info(`(SEARCH/ELASTICSEARCH) Creating index...`) WIKI.logger.info(`(SEARCH/ELASTICSEARCH) Creating index...`)
try { try {
@ -126,6 +127,7 @@ module.exports = {
} }
} catch (err) { } catch (err) {
WIKI.logger.error(`(SEARCH/ELASTICSEARCH) Index Check Error: `, _.get(err, 'meta.body.error', err)) WIKI.logger.error(`(SEARCH/ELASTICSEARCH) Index Check Error: `, _.get(err, 'meta.body.error', err))
WIKI.logger.error(err)
} }
}, },
/** /**
@ -217,7 +219,6 @@ module.exports = {
async created(page) { async created(page) {
await this.client.index({ await this.client.index({
index: this.config.indexName, index: this.config.indexName,
type: '_doc',
id: page.hash, id: page.hash,
body: { body: {
suggest: this.buildSuggest(page), suggest: this.buildSuggest(page),
@ -239,7 +240,6 @@ module.exports = {
async updated(page) { async updated(page) {
await this.client.index({ await this.client.index({
index: this.config.indexName, index: this.config.indexName,
type: '_doc',
id: page.hash, id: page.hash,
body: { body: {
suggest: this.buildSuggest(page), suggest: this.buildSuggest(page),
@ -261,7 +261,6 @@ module.exports = {
async deleted(page) { async deleted(page) {
await this.client.delete({ await this.client.delete({
index: this.config.indexName, index: this.config.indexName,
type: '_doc',
id: page.hash, id: page.hash,
refresh: true refresh: true
}) })
@ -274,13 +273,11 @@ module.exports = {
async renamed(page) { async renamed(page) {
await this.client.delete({ await this.client.delete({
index: this.config.indexName, index: this.config.indexName,
type: '_doc',
id: page.hash, id: page.hash,
refresh: true refresh: true
}) })
await this.client.index({ await this.client.index({
index: this.config.indexName, index: this.config.indexName,
type: '_doc',
id: page.destinationHash, id: page.destinationHash,
body: { body: {
suggest: this.buildSuggest(page), suggest: this.buildSuggest(page),
@ -349,7 +346,6 @@ module.exports = {
result.push({ result.push({
index: { index: {
_index: this.config.indexName, _index: this.config.indexName,
_type: '_doc',
_id: doc.id _id: doc.id
} }
}) })

17094
yarn.lock

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save