es添加新字段并更新历史数据的默认值

PUT /es_student_brands/_mapping
{
"properties": {
"is_auth": {
"type": "byte"
},
"auth_time": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
}
}
}

// 更新历史值为2

POST es_student_brands/_update_by_query?conflicts=proceed&wait_for_completion=false
{
"script": {
"lang": "painless",
"inline": "if (ctx._source.is_auth== null) {ctx._source.is_auth= '2'}"
}
}

//更新历史值为null

POST /es_student_brands/_update_by_query?conflicts=proceed&wait_for_completion=false
{
"script": {
"source": "ctx._source['auth_time'] = null",
"lang": "painless"
},
"query": {
"match_all": {}
}
}

 

 

# 更新es_student_brands中student_id为1,2,3的release_status为赋值为1
POST es_student_brands/_update_by_query
{
"conflicts": "proceed",
"query": {
"terms": {
"student_id": [1, 2, 3]
}
},
"script": {
"source": "ctx._source.release_status = 1",
"lang": "painless"
}
}
# 添加student_number字段
PUT /es_student_brands/_mapping
{
"properties": {
"student_number": {
"type": "keyword"
}
}
}
# 查询所有task任务
GET /_tasks/
# 查询task_id为1hV5QM34RqGoOvkFTgut4A:3571322322的任务
GET /_tasks/1hV5QM34RqGoOvkFTgut4A:3571322322
# 取消task_id为MVsKnLbQTPC8XVDHZZdSdg:1649293657
POST _tasks/MVsKnLbQTPC8XVDHZZdSdg:1649293657/_cancel
# 查询es_student_brands中release_status为null的student_id字段信息
POST es_student_brands/_search
{
"query": {
"bool": {
"must_not": [
{
"exists": { "field": "release_status" }
}
]
}
},
"_source": ["student_id"],
"size": 10000
}
# 查询es_student_brands中release_status为null的记录数
POST es_student_brands/_search
{
"query": {
"bool": {
"must_not": [
{
"exists": { "field": "release_status" }
}
]
}
},
"size": 0
}
# 更新es_student_brands索引里将release_status为null的值赋值为1
POST es_student_brands/_update_by_query?conflicts=proceed&wait_for_completion=false
{
"script": {
"lang": "painless",
"inline": "if (ctx._source.release_status== null) {ctx._source.release_status='1'}"
}
}
# 查询指定id学员信息
GET es_student_brands/_search
{
"_source": ["id", "release_status","c_user_id", "name", "phone", "sex", "age", "wechat", "qq", "email", "student_id", "owner_id", "promoter_id", "locking_id", "intention_id", "org_id", "org_dept_id", "province_id", "city_id", "district_id", "education_id", "remark", "channel_id", "project_id", "major_id", "subject_id", "is_new", "communicate_num", "is_active", "is_activation", "is_deal", "is_trigger", "is_invalid", "invalid_reason_id", "invalid_time", "lock_num", "receive_num", "is_common", "is_cache", "is_export", "protection_period", "valid_period", "next_contact_time", "last_distribution_time", "enterprise_id", "created_at", "created_by", "promoter_dept_id", "call_num", "inviter_id", "inviter_org_id", "activity_student_id", "exam_count", "job_direction", "job_direction_info", "job_department", "job_department_info"],
"from": 0,
"query": {
"bool": {
"must": [{
"term": {
"student_id": 418442105359239941
}
}, {
"term": {
"deleted_by": 0
}
}, {
"bool": {
"should": [{
"match": {
"enterprise_id": 0
}
}, {
"range": {
"protection_period": {
"format": "yyyy-MM-dd HH:mm:ss",
"lte": "2023-12-05 19:50:39"
}
}
}]
}
}],
"must_not": [{
"exists": {
"field": "deleted_at"
}
}]
}
},
"size": 10,
"sort": {
"id": {
"order": "desc"
}
}
}