elasticesearch--script脚本

elasticesearch–script脚本
查询语句

GET /索引名称/_search
{
  "from": 0,
  "size": 150,
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "blacklist": {
              "query": 1,
              "operator": "OR",
              "prefix_length": 0,
              "max_expansions": 50,
              "fuzzy_transpositions": true,
              "lenient": false,
              "zero_terms_query": "NONE",
              "auto_generate_synonyms_phrase_query": true,
              "boost": 1
            }
          }
        },
        {
          "range": {
            "lastLoginTime": {
              "from": "2022-10-17 13:55:23",
              "to": null,
              "include_lower": true,
              "include_upper": true,
              "boost": 1
            }
          }
        },
        {
          "range": {
            "lastLoginTime": {
              "from": null,
              "to": "2022-10-20 13:55:23",
              "include_lower": true,
              "include_upper": true,
              "boost": 1
            }
          }
        },
        {
          "range": {
            "enrollBirthday": {
              "from": "1972-01-01T00:00:00.000Z",
              "to": null,
              "include_lower": true,
              "include_upper": true,
              "boost": 1
            }
          }
        },
        {
          "range": {
            "enrollBirthday": {
              "from": null,
              "to": "2006-01-01T00:00:00.000Z",
              "include_lower": true,
              "include_upper": true,
              "boost": 1
            }
          }
        },
        {
          "bool": {
            "should": [
              {
                "match_phrase": {
                  "expectedPosition": {
                    "query": "影视传媒",
                    "slop": 0,
                    "zero_terms_query": "NONE",
                    "boost": 1
                  }
                }
              }
            ],
            "adjust_pure_negative": true,
            "boost": 1
          }
        },
        {
          "bool": {
            "should": [
              {
                "geo_distance": {
                  "expectWorkPlace.geoPoint": [
                    106.258864,
                    38.472247
                  ],
                  "distance": 20000,
                  "distance_type": "arc",
                  "validation_method": "STRICT",
                  "ignore_unmapped": false,
                  "boost": 1
                }
              },
              {
                "match": {
                  "expectWorkPlace.address": {
                    "query": "宁夏回族自治区银川市",
                    "operator": "AND",
                    "prefix_length": 0,
                    "max_expansions": 50,
                    "fuzzy_transpositions": true,
                    "lenient": false,
                    "zero_terms_query": "NONE",
                    "auto_generate_synonyms_phrase_query": true,
                    "boost": 1
                  }
                }
              }
            ],
            "adjust_pure_negative": true,
            "minimum_should_match": "1",
            "boost": 1
          }
        }
      ],
      "must_not": [
        {
          "terms": {
            "taskRegistList.taskId": [
              "1cadfa76-475e-4f30-9aa4-e049551b58d6"
            ],
            "boost": 1
          }
        }
      ],
      "adjust_pure_negative": true,
      "boost": 1
    }
  },
  "sort": [
    {
      "_geo_distance": {
        "expectWorkPlace.geoPoint": [
          {
            "lat": 38.472247,
            "lon": 106.258864
          }
        ],
        "unit": "km",
        "distance_type": "arc",
        "order": "asc",
        "validation_method": "STRICT",
        "ignore_unmapped": false
      }
    },
    {
      "outTime": {
        "order": "desc"
      }
    },
    {
      "enrollCreateTime": {
        "order": "asc"
      }
    }
  ],
  "collapse": {
    "field": "enrollRegistId"
  }
}```


```javascript
GET /索引名称/_search
{
  "from": 0,
  "size": 150,
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "blacklist": {
              "query": 1,
              "operator": "OR",
              "prefix_length": 0,
              "max_expansions": 50,
              "fuzzy_transpositions": true,
              "lenient": false,
              "zero_terms_query": "NONE",
              "auto_generate_synonyms_phrase_query": true,
              "boost": 1
            }
          }
        },
        {
          "range": {
            "lastLoginTime": {
              "from": "2022-10-06 14:01:24",
              "to": null,
              "include_lower": true,
              "include_upper": true,
              "boost": 1
            }
          }
        },
        {
          "range": {
            "lastLoginTime": {
              "from": null,
              "to": "2022-10-20 14:01:24",
              "include_lower": true,
              "include_upper": true,
              "boost": 1
            }
          }
        },
        {
          "range": {
            "enrollBirthday": {
              "from": "1972-01-01T00:00:00.000Z",
              "to": null,
              "include_lower": true,
              "include_upper": true,
              "boost": 1
            }
          }
        },
        {
          "range": {
            "enrollBirthday": {
              "from": null,
              "to": "2006-01-01T00:00:00.000Z",
              "include_lower": true,
              "include_upper": true,
              "boost": 1
            }
          }
        },
        {
          "bool": {
            "should": [
              {
                "match_phrase": {
                  "expectedPosition": {
                    "query": "影视传媒",
                    "slop": 0,
                    "zero_terms_query": "NONE",
                    "boost": 1
                  }
                }
              }
            ],
            "adjust_pure_negative": true,
            "boost": 1
          }
        },
        {
          "bool": {
            "should": [
              {
                "geo_distance": {
                  "expectWorkPlace.geoPoint": [
                    106.258864,
                    38.472247
                  ],
                  "distance": 35000,
                  "distance_type": "arc",
                  "validation_method": "STRICT",
                  "ignore_unmapped": false,
                  "boost": 1
                }
              },
              {
                "match": {
                  "expectWorkPlace.address": {
                    "query": "宁夏回族自治区银川市",
                    "operator": "AND",
                    "prefix_length": 0,
                    "max_expansions": 50,
                    "fuzzy_transpositions": true,
                    "lenient": false,
                    "zero_terms_query": "NONE",
                    "auto_generate_synonyms_phrase_query": true,
                    "boost": 1
                  }
                }
              }
            ],
            "adjust_pure_negative": true,
            "minimum_should_match": "1",
            "boost": 1
          }
        }
      ],
      "must_not": [
        {
          "terms": {
            "taskRegistList.taskId": [
              "1cadfa76-475e-4f30-9aa4-e049551b58d6"
            ],
            "boost": 1
          }
        },
        {
          "geo_distance": {
            "expectWorkPlace.geoPoint": [
              106.258864,
              38.472247
            ],
            "distance": 20000,
            "distance_type": "arc",
            "validation_method": "STRICT",
            "ignore_unmapped": false,
            "boost": 1
          }
        },
        {
          "terms": {
            "enrollRegistId": [
              389155,
              389186
            ],
            "boost": 1
          }
        },
        {
          "match": {
            "expectWorkPlace.address": {
              "query": "宁夏回族自治区银川市",
              "operator": "AND",
              "prefix_length": 0,
              "max_expansions": 50,
              "fuzzy_transpositions": true,
              "lenient": false,
              "zero_terms_query": "NONE",
              "auto_generate_synonyms_phrase_query": true,
              "boost": 1
            }
          }
        }
      ],
      "adjust_pure_negative": true,
      "boost": 1
    }
  },
  "sort": [
    {
      "_geo_distance": {
        "expectWorkPlace.geoPoint": [
          {
            "lat": 38.472247,
            "lon": 106.258864
          }
        ],
        "unit": "km",
        "distance_type": "arc",
        "order": "asc",
        "validation_method": "STRICT",
        "ignore_unmapped": false
      }
    },
    {
      "outTime": {
        "order": "desc"
      }
    },
    {
      "enrollCreateTime": {
        "order": "asc"
      }
    }
  ],
  "collapse": {
    "field": "enrollRegistId"
  }
}

更新数据语句

POST /索引名称/_update_by_query?conflicts=proceed
{
  "script": {
    "source": "ctx._source['commuting']=0",
    "lang": "painless"
  }
}

创建索引语句

PUT 索引名称
{
  "mappings": {
    "properties" : {
        "ageGroup" : {
          "type" : "long"
        },
        "blacklist" : {
          "type" : "long"
        },
        "commuting" : {
          "type" : "short"
        },
        "enrollBirthday" : {
          "type" : "date"
        },
        "enrollCreateTime" : {
          "type" : "date"
        },
        "enrollHobby" : {
          "type" : "text",
          "analyzer" : "ik_smart"
        },
        "enrollId" : {
          "type" : "long"
        },
        "enrollName" : {
          "type" : "keyword",
          "ignore_above" : 256
        },
        "enrollNum" : {
          "type" : "long"
        },
        "enrollPhone" : {
          "type" : "keyword",
          "ignore_above" : 256
        },
        "enrollProfile" : {
          "type" : "text",
          "analyzer" : "ik_smart"
        },
        "enrollRegistId" : {
          "type" : "long"
        },
        "enrollSex" : {
          "type" : "keyword",
          "ignore_above" : 256
        },
        "enrollWorking" : {
          "type" : "text",
          "analyzer" : "ik_smart"
        },
        "enrollmentNum" : {
          "type" : "long"
        },
        "expectWorkPlace" : {
          "properties" : {
            "address" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              },
              "analyzer" : "ik_smart"
            },
            "geoPoint" : {
              "type" : "geo_point"
            },
            "id" : {
              "type" : "integer"
            }
          }
        },
        "expectedPosition" : {
          "type" : "text",
          "analyzer" : "ik_smart"
        },
        "expectedSalary" : {
          "type" : "byte"
        },
        "lastLoginTime" : {
          "type" : "date",
          "format" : "yyyy-MM-dd HH:mm:ss"
        },
        "needDorm" : {
          "type" : "byte"
        },
        "nightShift" : {
          "type" : "byte"
        },
        "outTime" : {
          "type" : "date",
          "format" : "yyyy-MM-dd HH:mm:ss"
        },
        "parentExpectedPosition" : {
          "type" : "text",
          "analyzer" : "ik_smart"
        },
        "phoneCity" : {
          "type" : "keyword",
          "ignore_above" : 256
        },
        "phoneProvince" : {
          "type" : "keyword",
          "ignore_above" : 256
        },
        "phoneStatus" : {
          "type" : "byte"
        },
        "recommendNum" : {
          "type" : "long"
        },
        "registSource" : {
          "type" : "byte"
        },
        "registUserImage" : {
          "type" : "keyword",
          "index" : false
        },
        "tagList" : {
          "properties" : {
            "createTime" : {
              "type" : "date"
            },
            "id" : {
              "type" : "long"
            },
            "name" : {
              "type" : "keyword",
              "ignore_above" : 256
            },
            "path" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "updateTime" : {
              "type" : "date"
            }
          }
        },
        "taskRegistList" : {
          "properties" : {
            "employCreateTime" : {
              "type" : "date",
              "format" : "yyyy-MM-dd HH:mm:ss"
            },
            "enrollChannel" : {
              "type" : "byte"
            },
            "enrollCreateTime" : {
              "type" : "date",
              "format" : "yyyy-MM-dd HH:mm:ss"
            },
            "enrollStatus" : {
              "type" : "byte"
            },
            "personalType" : {
              "type" : "byte"
            },
            "realNameStatus" : {
              "type" : "byte"
            },
            "registId" : {
              "type" : "long"
            },
            "source" : {
              "type" : "byte"
            },
            "status" : {
              "type" : "byte"
            },
            "taskId" : {
              "type" : "keyword",
              "ignore_above" : 256
            },
            "taskName" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              },
              "analyzer" : "ik_smart"
            }
          }
        }
      }
  }
}

索引的字段类型创建的时候有问题,es本身不能修改索引中的字段类型,删除索引后把数据都删除了,这个时候不想删除索引该怎么办?
首先要滚动创建索引,然后给新索引创建一个别名,同步原索引的数据完成后,再去把原索引删除就可以了

POST _reindex
{
  "source": {
    "index": "删除的索引名称"
  },
  "dest": {
    "index": "新索引名称"
  }
} 


POST _aliases
{
  "actions": [
    {
      "add": {
        "index": "新索引名称",
        "alias": "regist_enroll"
      }
    }
  ]
}

POST _aliases
{
  "actions": [
    {
      "remove": {
        "index": "删除的索引名称",
        "alias": "regist_enroll"
      }
    }
  ]
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值