Add type to the highlight in the elasticsearch and three types are HIGHLIGHTS, REDACTION and NOTE

This commit is contained in:
Hongbo Wu
2023-03-13 15:15:47 +08:00
parent 30e52490e7
commit 71826148fd
3 changed files with 11 additions and 33 deletions

View File

@ -71,6 +71,12 @@ export enum ArticleSavingRequestStatus {
Deleted = 'DELETED',
}
export enum HighlightType {
Highlight = 'HIGHLIGHT',
Redaction = 'REDACTION', // allowing people to remove text from the page
Note = 'NOTE', // allowing people to add a note at the document level
}
export interface Label {
id: string
name: string
@ -94,6 +100,7 @@ export interface Highlight {
labels?: Label[]
highlightPositionPercent?: number | null
highlightPositionAnchorIndex?: number | null
type: HighlightType
html?: string | null
}

View File

@ -84,6 +84,10 @@
"userId": {
"type": "keyword"
},
"type": {
"type": "keyword",
"null_value": "HIGHLIGHT"
},
"quote": {
"type": "text",
"analyzer": "strip_html_analyzer"

View File

@ -148,41 +148,8 @@ const elasticMigration = esClient.indices
log('Elastic index mappings updated.')
})
})
.then(() => {
log('Adding default state to pages in elastic...')
return esClient
.update_by_query({
index: INDEX_ALIAS,
requests_per_second: 250,
scroll_size: 500,
timeout: '30m',
body: {
script: {
source: 'ctx._source.state = params.state',
lang: 'painless',
params: {
state: 'SUCCEEDED',
},
},
query: {
bool: {
must_not: [
{
exists: {
field: 'state',
},
},
],
},
},
},
})
.then(() => log('Default state added.'))
})
.catch((error) => {
log(`${chalk.red('Elastic migration failed: ')}${error.message}`, chalk.red)
const { appliedMigrations } = error
logAppliedMigrations(appliedMigrations)
process.exit(1)
})