POST mainindex/_update_by_query
{
    "script": {
        "source": "ctx._source.allwords = ctx._source.allwords.replace('–', ';');ctx._source.allwords = ctx._source.allwords.replace('–', ';');ctx._source.allwords = ctx._source.allwords.replace('،', ';');ctx._source.allwords = ctx._source.allwords.replace(',', ';');",
        "lang": "painless"
   },
   "query": {
     "bool": {
        "must": [
        {
          "exists": {
            "field":"allwords"
          }
        }
      ],
      "must_not": [
         {
          "bool": {
            "should": [
              {
                "term": {
                  "allwords.keyword": {
                    "value": ""
                  }
                }
              },
              {
                "term": {
                  "allwords.keyword": {
                    "value": ";"
                  }
                }
              }
            ]
          }
        }
      ]
     }
   }       
}
// query:
// گزینه اول: فیلد allwords باید وجود داشته باشد
// گزینه دوم: allwords.keyword نباید خالی باشد یا ; باشد
// Script:
// جایگزینی کاراکتر های - و , و ، با ;
// نتیحه: هر کجا که فیلد allwords وجود داشته باشد و خالی یا ; نباشد، کاراکتر هایی در آن ریپلیس خواهند شد


POST my-index/_update_by_query
{
    "script": {
        "source": "ctx._source.color.add('pink') ",
        "lang": "painless"
    },
    "query": {
        "bool": {
            "must": [
                {
                    "exists": {
                        "field": "color"
                    }
                }
            ]
        }
    }
}
// add To a array
POST my-index/1/_update_by_query
{
    "script": {
        "source": "ctx._source.array.add(['entity_id' :1, 'entity_title' : 'Title,'realation_type' : 'realation_type']); ",
        "lang": "painless"
    }
}
// ساخت آرای ای از آبجکت ها


POST my-index/1/_update_by_query
{
    "script": {
        "source": "try {String year = ''; if(ctx._source.eb_year != null) year =ctx._source.eb_year.trim().replace('/', '').replace('هـ', ''); int d = Integer.parseInt(year);ctx._source.eb_year = d;} catch (NumberFormatException nfe) {ctx._source.remove('eb_year');        }",
        "lang": "painless"
    }
}
// این اسکریپت در صورتی که فیلد eb_year int نباشد آن را حذف میکند



POST mainindex/_update_by_query
{
  "script": {
    "source": "    String allwords = ctx._source.allwords;    def a_chars = allwords.toCharArray();    int chars_len = a_chars.length;    ArrayList result = new ArrayList();    int last_dot = chars_len;    for(int i = chars_len -1; i>=-1; i--) {      if (i == -1 || a_chars[i] == (char) ';' ){          String t1 = allwords.substring(i+ 1, last_dot).trim();          if(t1 != '')            result.add(t1);        last_dot = i;              }    }             ctx._source.tags = result;    ",
    "lang": "painless"
  },
   "query": {
     "bool": {
        "must": [
        {
          "exists": {
            "field":"allwords"
          }
        }
      ],
      "must_not": [
         {
          "bool": {
            "should": [
              {
                "term": {
                  "allwords.keyword": {
                    "value": ""
                  }
                }
              },
              {
                "term": {
                  "allwords.keyword": {
                    "value": ";"
                  }
                }
              }
            ]
          }
        }
      ]
     }
   }
   
    
}
// اگر فیلد allwords وجود داشته باشد، اسکریپت اجرا میشود
// String allwords = ctx._source.allwords;    def a_chars = allwords.toCharArray();    int chars_len = a_chars.length;
// chars_len = تعداد کاراکتر های allwords
// ArrayList result = new ArrayList(); int last_dot = chars_len;
// result --> یک آرایه 
// for(int i = chars_len -1; i>=-1; i--) { if (i == -1 || a_chars[i] == (char) ';' ){String t1 = allwords.substring(i+ 1, last_dot).trim();          if(t1 != '')            result.add(t1);last_dot = i;
// این کد allwords را از آخر به اول میخواند و با ; اسپلیت میکند و در آرایه result میریزد
// البته میتوان از 
// a_chars,split(';')
// نیز استفاده کرد