Created
January 28, 2018 23:10
-
-
Save roalcantara/39e275165a4603ca8268f5b92b8e517b to your computer and use it in GitHub Desktop.
ElasticSearch: Append to array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const created_by = '12345566'; | |
const script = 'if (ctx._source.raters == null) { ctx._source.raters = [] } \ | |
if (ctx._source.raters.indexOf(params.created_by) == -1) {\ | |
ctx._source.raters.add(params)\ | |
}'; | |
return this.client.update({ | |
index: 'index', | |
type: 'type', | |
id: 'key', | |
body: { | |
script: { | |
lang: 'painless', | |
source: script, | |
params: { | |
created_by: created_by | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment