1.创建index(database)
curl -XPUT 'http://url:9200/index_name?pretty'
{
"settings": {
"number_of_shards": 32,
"number_of_replicas": 1
}
}
?
2.查看创建好的索引(database)信息
curl -XGET 'http://url:9200/index_name?pretty'
3.修改settings
curl -XPUT 'http://url:9200/index_name/_settings?pretty'
{
? ? "index" : {
? ? ? ? "number_of_replicas" : 1
? ? }
}
4.创建type(table)
curl -XPUT 'http://url:9200/index_name/_mapping/type_name?pretty'
{?? ?
? ? "index_name": {
?? ??? ?"dynamic": "false",
?? ??? ??? ?"properties": {
?? ??? ??? ??? ?"is_hide": {
?? ??? ??? ??? ??? ?"store": true,
?? ??? ??? ??? ??? ?"type": "integer"
?? ??? ??? ??? ?},
?? ??? ??? ??? ?"summary": {
?? ??? ??? ??? ??? ?"analyzer": "standard",
?? ??? ??? ??? ??? ?"type": "text"
?? ??? ??? ??? ?},
?? ??? ??? ??? ?"image": {
?? ??? ??? ??? ??? ?"store": true,
?? ??? ??? ??? ??? ?"type": "keyword"
?? ??? ??? ??? ?},
?? ??? ??? ??? ?"classify_id": {
?? ??? ??? ??? ??? ?"store": true,
?? ??? ??? ??? ??? ?"type": "keyword"
?? ??? ??? ??? ?},
?? ??? ??? ??? ?"editTime": {
?? ??? ??? ??? ??? ?"format": "yyyy-MM-dd HH:mm:ss",
?? ??? ??? ??? ??? ?"store": true,
?? ??? ??? ??? ??? ?"type": "date"
?? ??? ??? ??? ?},
?? ??? ??? ??? ?"version": {
?? ??? ??? ??? ??? ?"store": true,
?? ??? ??? ??? ??? ?"type": "keyword"
?? ??? ??? ??? ?},
?? ??? ??? ??? ?"is_top": {
?? ??? ??? ??? ??? ?"store": true,
?? ??? ??? ??? ??? ?"type": "integer"
?? ??? ??? ??? ?},
?? ??? ??? ??? ?"tags": {
?? ??? ??? ??? ??? ?"store": true,
?? ??? ??? ??? ??? ?"type": "keyword"
?? ??? ??? ??? ?},
?? ??? ??? ??? ?"auto_id": {
?? ??? ??? ??? ??? ?"store": true,
?? ??? ??? ??? ??? ?"type": "long"
?? ??? ??? ??? ?},
?? ??? ??? ??? ?"top_end_time": {
?? ??? ??? ??? ??? ?"format": "yyyy-MM-dd HH:mm:ss",
?? ??? ??? ??? ??? ?"store": true,
?? ??? ??? ??? ??? ?"type": "date"
?? ??? ??? ??? ?},
?? ??? ??? ??? ?"infoSWordStatus": {
?? ??? ??? ??? ??? ?"store": true,
?? ??? ??? ??? ??? ?"type": "integer"
?? ??? ??? ??? ?},
?? ??? ??? ??? ?"wiki_info_id": {
?? ??? ??? ??? ??? ?"store": true,
?? ??? ??? ??? ??? ?"type": "long"
?? ??? ??? ??? ?},
?? ??? ??? ??? ?"r_version": {
?? ??? ??? ??? ??? ?"store": true,
?? ??? ??? ??? ??? ?"type": "integer"
?? ??? ??? ??? ?},
?? ??? ??? ??? ?"name": {
?? ??? ??? ??? ??? ?"store": true,
?? ??? ??? ??? ??? ?"type": "keyword"
?? ??? ??? ??? ?},
?? ??? ??? ??? ?"secret_class": {
?? ??? ??? ??? ??? ?"store": true,
?? ??? ??? ??? ??? ?"type": "integer"
?? ??? ??? ??? ?},
?? ??? ??? ??? ?"infoSWord": {
?? ??? ??? ??? ??? ?"analyzer": "standard",
?? ??? ??? ??? ??? ?"type": "text"
?? ??? ??? ??? ?},
?? ??? ??? ??? ?"classifyName": {
?? ??? ??? ??? ??? ?"store": true,
?? ??? ??? ??? ??? ?"type": "keyword"
?? ??? ??? ??? ?},
?? ??? ??? ??? ?"read_count": {
?? ??? ??? ??? ??? ?"store": true,
?? ??? ??? ??? ??? ?"type": "integer"
?? ??? ??? ?}
?? ?}
}
}
5.按照条件筛选 reindex
curl -XPOST 'http://url:9200/_reindex'
{
? ? "source": {
? ? ? ? "index": "源index",
? ? ? ? "type": "源index",
? ? ? ? "size": "10000",
? ? ? ? "query": {
? ? ? ? ? ? "range": {
? ? ? ? ? ? ? ? "auto_id": {
? ? ? ? ? ? ? ? ? ? "lte": 500
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? },
? ? "dest": {
? ? ? ? "index": "新index",
? ? ? ? "type": "新index",
? ? ? ? "op_type": "create"
? ? }
}
6.删除索引全部数据
curl -XPOST 'http://url:9200/index_name/type_name/_delete_by_query?pretty
{
? ? "query" : {?
? ? ? ? "match_all" : {}
? ? }
}
6.1批量删除数据
curl -XPOST 'http://url:9200/index_name/type_name/_delete_by_query?pretty'
{
? ? "query": {
? ? ? ? ? ? "range": {
? ? ? ? ? ? ? ? "pubtime": {
? ? ? ? ? ? ? ? ? ? "gte": "2021-01-01 00:00:00",
? ? ? ? ? ? ? ? ? ? "lt":"2021-02-01 00:00:00"
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
}
7.查看所有模板
curl -XGET http://url:9200/_cat/templates?pretty
8.查看某一个模板
?
curl -XGET http://url:9200/_template/mblog_info_merged_template?pretty
?
9.删除某一个模板
curl -XDELETE http://url:9200/_template/proj-zx-integration-template_appdata
10.修改配置
curl -XPUT http://10.129.194.1:9200/index_name/_settings -d?
'{"index.number_of_replicas": 5}'?
11.一个ES索引由若干个分片组成,一个分片有若干个Lucene分段,较大的Lucene分段可以更有效的存储数据。
使用_forcemergeAPI 来对分段执行合并操作,通常,我们将分段合并为一个单个的分段:max_num_segments=1
11.1查看某个index的forceMerge情况?
GET /_cat/segments/myindex?v&s=prirep,shard
11.2首先查看我们的index(可以使用正则匹配)当前有多少个segment:
GET _cat/segments/myindex?v&h=shard,segment,size,size.memory
返回结果大约有300个segment条目数。
11.3执行forcemerge:
POST myindex/_forcemerge?max_num_segments=1
这个过程可能执行的时间比较久。
11.4查看各个节点forceMerge的线程数:
GET _cat/thread_pool/force_merge?v&s=name
11.5查看所有index的segment(段)情况和正在进行merge的文档数:
GET /_cat/indices/?s=segmentsCount:desc&v&h=index,segmentsCount,segmentsMemory,memoryTotal,mergesCurrent,mergesCurrentDocs,storeSize,p,r
从返回结果可以看到当前正在进行myindexmerge操作,segmentsCount数量会越来越小。最终会变成每个分片只有一个segment。
11.6查看forceMerge任务详情
GET _tasks?detailed=true&actions=*forcemerge
12.查看索引情况
http://url:9200/_cat/indices?v
?
|