wsl --set-version Ubuntu-18.04 2
(这条命令只有内部预览版才有效)wsl -l -v
查看wsl版本PS C:\Users\L1yp> wsl -l -v
NAME STATE VERSION
* Ubuntu-18.04 Running 2
docker-desktop Running 2
docker-desktop-data Running 2
下载地址:https://liangyongpeng.com/html/download.html?last_id=0&pid=2
官方下载可能有点慢。
sudo cp /etc/apt/source.list /etc/apt/source.list.back
vim /etc/apt/source.list
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu bionic stable
# deb-src [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu bionic stable
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt-get install docker-ce
https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html
docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.6.2
docker inspect --format='{{.NetworkSettings.IPAddress}}' [ES容器ID]
PUT /article
{
"settings": {
"number_of_replicas": 0,
"number_of_shards": 1
},
"mappings": {
"properties": {
"id":{
"type": "long",
"index": false
},
"title":{
"type": "text",
"analyzer": "ik_max_word"
},
"preface":{
"type": "text",
"analyzer": "ik_max_word"
},
"uri":{
"type": "keyword",
"index": false
},
"gmt_modified":{
"type": "date",
"index": true,
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis",
"locale": "zh_CN",
"doc_values": true
}
}
}
}
############response############
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "article"
}
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html
以下两种,如果<_id>已存在,ES会更新文档并递增
_version
版本号
PUT /<index>/_doc/<_id>
:指定文档ID
POST /<index>/_doc/
:自动生成文档ID
PUT /article/_doc/1
{
"id": 1,
"title": "了解如何使用常用线程池",
"preface": "ThreadPoolExecutor ThreadPoolExecutor线程池状态线程池状态转换线程池参数线程池类型ThreadPoolExecutor线程池状态RUNNING:接受新任务并且处理阻塞队列里的任务SHUTDOWN:拒绝新任务但是处理阻塞队列里的任务STOP:拒绝新任务并抛弃阻塞队列里的任务,同时中断正在处理的任务TIDYING:所有任务都执行完(包含阻塞队列里的...",
"uri": "/html/detail/threadpool.html",
"gmt_midified": "2020-04-04 20:20:20"
}
############response############
{
"_index" : "article", # 索引名称
"_type" : "_doc", # ES现在只支持_doc文档类型
"_id" : "1", # 已添加文档的唯一标识
"_version" : 2, # 更新就递增
"result" : "updated", # created/updated,创建成功/更新成功
"_shards" : {
"total" : 1, # 分片总数
"successful" : 1, # 分片复制成功数量
"failed" : 0 # 分片复制失败数量
},
"_seq_no" : 1, # 文档的操作序列化,防止乐观锁的ABA
"_primary_term" : 1
}
以下两种,如果<_id>已存在,ES会抛出异常,相当于putIfAbsent
PUT /<index>/_create/<_id>
POST /<index>/_create/<_id>
PUT /article/_create/1
{
"id": 1,
"title": "了解如何使用常用线程池",
"preface": "ThreadPoolExecutor ThreadPoolExecutor线程池状态线程池状态转换线程池参数线程池类型ThreadPoolExecutor线程池状态RUNNING:接受新任务并且处理阻塞队列里的任务SHUTDOWN:拒绝新任务但是处理阻塞队列里的任务STOP:拒绝新任务并抛弃阻塞队列里的任务,同时中断正在处理的任务TIDYING:所有任务都执行完(包含阻塞队列里的...",
"uri": "/html/detail/threadpool.html",
"gmt_midified": "2020-04-04 20:20:20"
}
############response############
{
"error" : {
"root_cause" : [
{
"type" : "version_conflict_engine_exception",
"reason" : "[1]: version conflict, document already exists (current version [2])",
"index_uuid" : "LTY0RwRcQQScWT6ay2ob4A",
"shard" : "0",
"index" : "article"
}
],
"type" : "version_conflict_engine_exception",
"reason" : "[1]: version conflict, document already exists (current version [2])",
"index_uuid" : "LTY0RwRcQQScWT6ay2ob4A",
"shard" : "0",
"index" : "article"
},
"status" : 409
}
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html
POST /<index>/_update/<_id>
POST /article/_update/1
{
"doc" : {
"title": "了解如何使用常用线程池2"
}
}
############response############
{
"_index" : "article",
"_type" : "_doc",
"_id" : "1",
"_version" : 3,
"result" : "updated",
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 2,
"_primary_term" : 1
}
通过脚本更新
POST /article/_update/1
{
"script" : {
"source": "ctx._source.title += params.count",
"lang": "painless",
"params" : {
"count" : 4
}
}
}
############response############
{
"_index" : "article",
"_type" : "_doc",
"_id" : "1",
"_version" : 4,
"result" : "updated",
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 3,
"_primary_term" : 1
}
upsert操作:
- 若文档不存在,则插入[upsert]结构。
- 若文档存在,则执行更新脚本。
POST /article/_update/2
{
"script" : {
"source": "ctx._source.title += params.count",
"lang": "painless",
"params" : {
"count" : 4
}
},
"upsert" : {
"id": 2,
"title": "了解如何使用常用线程池2",
"preface": "ThreadPoolExecutor ThreadPoolExecutor线程池状态线程池状态转换线程池参数线程池类型ThreadPoolExecutor线程池状态RUNNING:接受新任务并且处理阻塞队列里的任务SHUTDOWN:拒绝新任务但是处理阻塞队列里的任务STOP:拒绝新任务并抛弃阻塞队列里的任务,同时中断正在处理的任务TIDYING:所有任务都执行完(包含阻塞队列里的2...",
"uri": "/html/detail/threadpool.html",
"gmt_midified": "2020-04-04 20:21:20"
}
}
############response############
{
"_index" : "article",
"_type" : "_doc",
"_id" : "2",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 4,
"_primary_term" : 1
}
############response2############
{
"_index" : "article",
"_type" : "_doc",
"_id" : "2",
"_version" : 2,
"result" : "updated",
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 5,
"_primary_term" : 1
}
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html
POST /article/_update_by_query?conflicts=proceed
{
"script": {
"source": "ctx._source.title += params.count",
"lang": "painless",
"params" : {
"count" : 4
}
},
"query": {
"match": {
"title" : "线程池"
}
}
}
############response2############
# https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html#docs-update-by-query-response-body
{
"took" : 17, # 操作耗时
"timed_out" : false,
"total" : 2, # 成功处理的Document数量
"updated" : 2, # 成功更新的Document数量
"deleted" : 0, # 成功删除的Document数量
"batches" : 1, # 通过查询更新拉回的滚动响应数
"version_conflicts" : 0, # 按查询进行更新的版本冲突数
"noops" : 0, # 由于用于查询更新的脚本返回 的值而忽略的文档数
"retries" : {
"bulk" : 0, #
"search" : 0
},
"throttled_millis" : 0, # 请求睡到符合 的毫秒数
"requests_per_second" : -1.0, # 查询更新期间每秒有效执行的请求数
"throttled_until_millis" : 0,
"failures" : [ ]
}
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html
DELETE /<index>/_doc/<_id>
DELETE /article/_doc/2
{
"_index" : "article",
"_type" : "_doc",
"_id" : "2",
"_version" : 5,
"result" : "deleted",
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 10,
"_primary_term" : 1
}
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html
POST /article/_delete_by_query
{
"query": {
"match": {
"title": "线程"
}
}
}
############response############
{
"took" : 24,
"timed_out" : false,
"total" : 4,
"deleted" : 4,
"batches" : 1,
"version_conflicts" : 0,
"noops" : 0,
"retries" : {
"bulk" : 0,
"search" : 0
},
"throttled_millis" : 0,
"requests_per_second" : -1.0,
"throttled_until_millis" : 0,
"failures" : [ ]
}
GET /article/_search
{
"query":{
"match_all":{}
}
}
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html
req
GET /_mget
{
"docs" : [
{
"_index" : "article",
"_id" : "1"
},
{
"_index" : "article",
"_id" : "2"
}
]
}
GET /article/_mget
{
"ids":["1", "2"]
}
GET /article/_doc/_mget
{
"docs" : [
{
"_id" : "1"
},
{
"_id" : "2"
}
]
}
GET /_mget
{
"docs" : [
{
"_index" : "article",
"_type" : "_doc",
"_id" : "1",
"_source" : false
},
{
"_index" : "article",
"_type" : "_doc",
"_id" : "2",
"_source" : ["title", "preface"]
},
{
"_index" : "article",
"_type" : "_doc",
"_id" : "3",
"_source" : {
"include": ["title"]
}
}
]
}
resp
{
"docs" : [
{
"_index" : "article",
"_type" : "_doc",
"_id" : "1",
"_version" : 3,
"_seq_no" : 26,
"_primary_term" : 1,
"found" : true,
"_source" : {
"id" : 1,
"title" : "了解如何使用常用线程池",
"preface" : "ThreadPoolExecutor ThreadPoolExecutor线程池状态线程池状态转换线程池参数线程池类型ThreadPoolExecutor线程池状态RUNNING:接受新任务并且处理阻塞队列里的任务SHUTDOWN:拒绝新任务但是处理阻塞队列里的任务STOP:拒绝新任务并抛弃阻塞队列里的任务,同时中断正在处理的任务TIDYING:所有任务都执行完(包含阻塞队列里的...",
"uri" : "/html/detail/threadpool.html",
"gmt_midified" : "2020-04-04 20:20:20"
}
},
{
"_index" : "article",
"_type" : "_doc",
"_id" : "2",
"_version" : 3,
"_seq_no" : 27,
"_primary_term" : 1,
"found" : true,
"_source" : {
"id" : 2,
"title" : "了解JVM垃圾回收的细节",
"preface" : "JVM垃圾回收 垃圾收集理论对象已死吗?引用计数算法 给对象添加一个引用计数器,每当有一个地方引用它时,计数器加1,引用失效计数器减1,任何时刻计数器为0的对象就是不可能再被使用的。应用场景:微软的COM(Component Object Model)技术ActionScript3的FlashPlayer缺点:无法解决循环引用。可达性分析算法 通过一系列GC Roots的对象...",
"uri" : "/html/detail/jvm-gc.html",
"gmt_midified" : "2020-04-04 20:20:20"
}
}
]
}
GET /article/_search
{
"query": {
"bool": {
"must": [
{ "match": { "title": "了解" }}
],
"filter": [
{ "range": { "gmt_modified": { "gte": "2020-03-04 20:20:20" }}}
]
}
}
}
resp
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 0.7046783,
"hits" : [
{
"_index" : "article",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.7046783,
"_source" : {
"id" : 1,
"title" : "了解如何使用常用线程池",
"preface" : "ThreadPoolExecutor ThreadPoolExecutor线程池状态线程池状态转换线程池参数线程池类型ThreadPoolExecutor线程池状态RUNNING:接受新任务并且处理阻塞队列里的任务SHUTDOWN:拒绝新任务但是处理阻塞队列里的任务STOP:拒绝新任务并抛弃阻塞队列里的任务,同时中断正在处理的任务TIDYING:所有任务都执行完(包含阻塞队列里的...",
"uri" : "/html/detail/threadpool.html",
"gmt_modified" : "2020-04-04 20:20:20"
}
}
]
}
}
POST /article/_search?size=0
{
"aggs" : {
"id" : {
"filter" : { "match": { "title": "了解" } },
"aggs" : {
"avg_price" : { "avg" : { "field" : "id" } }
}
}
}
}
PUT /article
{
"settings": {
"number_of_replicas": 0,
"number_of_shards": 1
},
"mappings": {
"properties": {
"id":{
"type": "long",
"index": false
},
"title":{
"type": "text",
"analyzer": "ik_max_word"
},
"preface":{
"type": "text",
"analyzer": "ik_max_word"
},
"uri":{
"type": "keyword",
"index": false
},
"gmt_modified":{
"type": "date",
"index": true,
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis",
"locale": "zh_CN",
"doc_values": true
}
}
}
}
PUT /article/_doc/1
{
"id" : 1,
"title" : "了解如何使用常用线程池",
"preface" : "ThreadPoolExecutor ThreadPoolExecutor线程池状态线程池状态转换线程池参数线程池类型ThreadPoolExecutor线程池状态RUNNING:接受新任务并且处理阻塞队列里的任务SHUTDOWN:拒绝新任务但是处理阻塞队列里的任务STOP:拒绝新任务并抛弃阻塞队列里的任务,同时中断正在处理的任务TIDYING:所有任务都执行完(包含阻塞队列里的...",
"uri" : "/html/detail/threadpool.html",
"gmt_modified" : "2020-04-04 20:20:20"
}
PUT /article/_doc/2
{
"id" : 2,
"title" : "了解JVM垃圾回收的细节",
"preface" : "JVM垃圾回收 垃圾收集理论对象已死吗?引用计数算法 给对象添加一个引用计数器,每当有一个地方引用它时,计数器加1,引用失效计数器减1,任何时刻计数器为0的对象就是不可能再被使用的。应用场景:微软的COM(Component Object Model)技术ActionScript3的FlashPlayer缺点:无法解决循环引用。可达性分析算法 通过一系列GC Roots的对象...",
"uri" : "/html/detail/jvm-gc.html",
"gmt_modified" : "2020-02-04 20:20:20"
}
PUT /article/_doc/3
{
"id" : 3,
"title" : "Concurrenthashmap高级应用",
"preface" : "ConcurrentHashMap高级应用 ConcurrentHashMap高级应用computeIfAbsentcomputeIfPresentcomputemergeConcurrentHashMap高级应用 一直以来想做的一个功能是,对用户调用API的次数做限制,由于调用很频繁,读写次数基本上相等,MySQL这种数据库肯定不能解决。 接触JAVA...",
"uri" : "/html/detail/ConcurrentHashMap-Advanced.html",
"gmt_modified" : "2020-03-04 20:20:20"
}
PUT /article/_doc/4
{
"id" : 4,
"title" : "破解最强文本编辑器Sublime3",
"preface" : "sublime-3207 sublime 3207下载sublime3,高速下载修改hosts文件C:WindowsSystem32driversetc127.0.0.1 www.sublimetext.com127.0.0.1 sublimetext.com127.0.0.1 sublimehq.com127.0.0.1 telemetry.sub...",
"uri" : "/html/detail/sublime-crack.html",
"gmt_modified" : "2020-04-04 20:20:20"
}
未完待续....