forked from onebirdrocks/geektime-ELK
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d3de9b
commit b2c9267
Showing
1 changed file
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
# Update by Query & Reindex | ||
## 课程demo | ||
``` | ||
DELETE blogs/ | ||
# 写入文档 | ||
PUT blogs/_doc/1 | ||
{ | ||
"content":"Hadoop is cool", | ||
"keyword":"hadoop" | ||
} | ||
# 查看 Mapping | ||
GET blogs/_mapping | ||
# 修改 Mapping,增加子字段,使用英文分词器 | ||
PUT blogs/_mapping | ||
{ | ||
"properties" : { | ||
"content" : { | ||
"type" : "text", | ||
"fields" : { | ||
"english" : { | ||
"type" : "text", | ||
"analyzer":"english" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
# 写入文档 | ||
PUT blogs/_doc/2 | ||
{ | ||
"content":"Elasticsearch rocks", | ||
"keyword":"elasticsearch" | ||
} | ||
# 查询新写入文档 | ||
POST blogs/_search | ||
{ | ||
"query": { | ||
"match": { | ||
"content.english": "Elasticsearch" | ||
} | ||
} | ||
} | ||
# 查询 Mapping 变更前写入的文档 | ||
POST blogs/_search | ||
{ | ||
"query": { | ||
"match": { | ||
"content.english": "Hadoop" | ||
} | ||
} | ||
} | ||
# Update所有文档 | ||
POST blogs/_update_by_query | ||
{ | ||
} | ||
# 查询之前写入的文档 | ||
POST blogs/_search | ||
{ | ||
"query": { | ||
"match": { | ||
"content.english": "Hadoop" | ||
} | ||
} | ||
} | ||
# 查询 | ||
GET blogs/_mapping | ||
PUT blogs/_mapping | ||
{ | ||
"properties" : { | ||
"content" : { | ||
"type" : "text", | ||
"fields" : { | ||
"english" : { | ||
"type" : "text", | ||
"analyzer" : "english" | ||
} | ||
} | ||
}, | ||
"keyword" : { | ||
"type" : "keyword" | ||
} | ||
} | ||
} | ||
DELETE blogs_fix | ||
# 创建新的索引并且设定新的Mapping | ||
PUT blogs_fix/ | ||
{ | ||
"mappings": { | ||
"properties" : { | ||
"content" : { | ||
"type" : "text", | ||
"fields" : { | ||
"english" : { | ||
"type" : "text", | ||
"analyzer" : "english" | ||
} | ||
} | ||
}, | ||
"keyword" : { | ||
"type" : "keyword" | ||
} | ||
} | ||
} | ||
} | ||
# Reindx API | ||
POST _reindex | ||
{ | ||
"source": { | ||
"index": "blogs" | ||
}, | ||
"dest": { | ||
"index": "blogs_fix" | ||
} | ||
} | ||
GET blogs_fix/_doc/1 | ||
# 测试 Term Aggregation | ||
POST blogs_fix/_search | ||
{ | ||
"size": 0, | ||
"aggs": { | ||
"blog_keyword": { | ||
"terms": { | ||
"field": "keyword", | ||
"size": 10 | ||
} | ||
} | ||
} | ||
} | ||
# Reindx API,version Type Internal | ||
POST _reindex | ||
{ | ||
"source": { | ||
"index": "blogs" | ||
}, | ||
"dest": { | ||
"index": "blogs_fix", | ||
"version_type": "internal" | ||
} | ||
} | ||
# 文档版本号增加 | ||
GET blogs_fix/_doc/1 | ||
# Reindx API,version Type Internal | ||
POST _reindex | ||
{ | ||
"source": { | ||
"index": "blogs" | ||
}, | ||
"dest": { | ||
"index": "blogs_fix", | ||
"version_type": "external" | ||
} | ||
} | ||
# Reindx API,version Type Internal | ||
POST _reindex | ||
{ | ||
"source": { | ||
"index": "blogs" | ||
}, | ||
"dest": { | ||
"index": "blogs_fix", | ||
"version_type": "external" | ||
}, | ||
"conflicts": "proceed" | ||
} | ||
# Reindx API,version Type Internal | ||
POST _reindex | ||
{ | ||
"source": { | ||
"index": "blogs" | ||
}, | ||
"dest": { | ||
"index": "blogs_fix", | ||
"op_type": "create" | ||
} | ||
} | ||
GET _tasks?detailed=true&actions=*reindex | ||
``` |