elasticsearch field add(1)
2022, Mar 19
elasticsearch
[๊ณตํต]
๊ธฐ์กด ๋ฐ์ดํฐ ๋ฐฑ์ ์ ์งํํฉ๋๋ค.
์ค๋ ์ท ๋ฐฑ์ ๋ฐฉ์์ โ์ฌ๊ธฐโ ์ฐธ๊ณ ํ์ธ์.
[๊ธฐ์กด ๋ฐ์ดํฐ์ ์ถ๊ฐํ๋ ๋ฐฉ์]
1. ํ์ฌ ์ ์ฉ๋ ๋งตํ ์ ๋ณด๋ฅผ ์กฐํํ๋ค.
GET attic_ticket/_mapping
2. ์์์ ์กฐํํ ๋งตํ ์ ๋ณด๋ฅผ ์ฐธ๊ณ ํด์, depth์ ๋ง๊ฒ ์ปฌ๋ผ์ ์ถ๊ฐํ๋ค.
PUT attic_ticket/_mappings
{
"properties": {
"customer" : {
"type":"nested",
"properties": {
"messengerId": { // customer์ messengerId ์ปฌ๋ผ ์ถ๊ฐ
"type": "text"
}
}
}
}
}
3. ์ ์ถ๊ฐ๋์๋์ง ํ์ธํ๋ค
GET attic_ticket/_mapping
4. ๊ธฐ์กด ๋ฐ์ดํฐ์ ์ถ๊ฐํ ํ๋๋ฅผ ์ ๋ฐ์ดํธ ํ๋ค.( multiple update )
POST attic_ticket/_update_by_query
{
"script": "ctx._source.customer.messengerId = ''"
}
** (ํ๋๊ฐ ๋ฐฐ์ด์ธ ๊ฒฝ์ฐ) **
5-1. ๊ธฐ์กด ๋ฐฐ์ด ์ญ์
POST attic_message/_update_by_query
{
"script": {
"source": "ctx._source.remove('metaarray')"
},
"query":{
"bool": {
"should": [
{
"terms": {
"channelUrl": [
"92095428-d647-466c-a054-e1e984dd48b1"
]
}
}
]
}
}
}
5-2. ๋ฐฐ์ด ์ด๊ธฐํ
POST attic_message/_update_by_query
{
"script": "ctx._source.metaarray = []",
"query":{
"bool": {
"should": [
{
"terms": {
"channelUrl": [
"92095428-d647-466c-a054-e1e984dd48b1"
]
}
}
]
}
}
}
5-3. ๋ฐฐ์ด์ ๊ฐ ์ถ๊ฐ
POST attic_message/_update_by_query
{
"script": {
"source":"ctx._source.metaarray.add(params)",
"params": {
"key": "templateMessage",
"value":[
"{~~~~~~~~~~}"
]
}
},
"query":{
"bool": {
"should": [
{
"terms": {
"channelUrl": [
"92095428-d647-466c-a054-e1e984dd48b1"
]
}
}
]
}
}
}
5. ๊ฒ์ฆ
- ์ผ๋ถ ํฐ์ผ์๋ง ์ถ๊ฐํ ํ๋์ ๊ฐ์ ์ ๋ฐ์ดํธํด๋ณธ๋ค.
POST attic_ticket/_update_by_query
{
"script": {
"source":"ctx._source.customer.messengerId = 'honggildong'"
},
"query":{ // ์ผ๋ถ ticket์๋ง ๊ฐ์ ์
๋ฐ์ดํธํ๊ณ
"term":{
"ticketId":"63af9a77-845b-4ca5-b692-0d3e5cc7d398"
}
}
}
- ์ถ๊ฐํ ๊ฐ์ผ๋ก ๊ฒ์ํด๋ณธ๋ค.
GET attic_ticket/_search
{
"query" : {
"bool": {
"should":[{
"terms":{
"ticketId":["63af9a77-845b-4ca5-b692-0d3e5cc7d398"],"boost":1.0
}
}]
}
}
}
์ฐธ๊ณ ) https://esbook.kimjmin.net/04-data/4.3-_bulk