这里以索引名为data_index
为例,elasticsearch的地址为http://10.47.0.96:9200
,版本为Elasticsearch 7.1.1
。
索引
1.创建索引
1)创建名为data_index
的索引
curl -XPUT 'http://10.47.0.96:9200/data_index'
2)创建索引同时对索引进行设置、创建映射
curl -H 'Content-Type: application/json' -XPUT 'http://10.47.0.96:9200/data_index' -d '
{
"settings": {
"analysis": {
"analyzer": {
"dataArchives_analyzer": {
"tokenizer": "dataArchives_tokenizer"
}
},
"tokenizer": {
"dataArchives_tokenizer": {
"type": "ngram",
"min_gram": 3,
"max_gram": 3,
"token_chars": [
"letter",
"digit"
]
}
}
}
},
"mappings": {
"properties": {
"id_number": {
"type": "text",
"analyzer": "dataArchives_analyzer",
"search_analyzer": "dataArchives_analyzer"
},
"name": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"birthday": {
"type": "text"
}
}
}
}'
2.删除索引
1)删除
curl -XDELETE 'http://10.47.0.96:9200/data_index'
2) 删除多个指定索引
curl -XDELETE 'http://10.47.0.96:9200/data_index,data_index1,data_index2'
3)删除所有索引
curl -XDELETE 'http://10.47.0.96:9200/_all'
3.打开索引
curl -XPOST 'http://10.47.0.96:9200/data_index/_open'
4.关闭索引
curl -XPOST 'http://10.47.0.96:9200/data_index/_close'
映射
1.创建映射
curl -H 'Content-Type: application/json' -XPUT 'http://10.47.0.96:9200/data_index/_mapping' -d'
{
"properties": {
"attachment.content": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart"
},
"fileName": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart"
}
}
}'
2.查看映射
curl -H 'Content-Type: application/json' -XGET 'http://10.47.0.96:9200/data_index/_mapping?pretty'
3.删除映射
映射创建后,正常是无法删除的,详见:Elasticsearch Reference [7.1] » Deleted pages » Delete Mapping;
设置
如果要对索引进行设置,可以参考上面索引->创建索引-创建索引同时对索引进行设置、创建映射
部分,在创建索引时进行设置,否则需要先close索引,再进行配置:
curl -H 'Content-Type: application/json' -XPUT 'http://10.47.0.96:9200/data_archives_jw_reporter_info/_settings' -d'
{
"analysis": {
"analyzer": {
"dataArchives_analyzer": {
"tokenizer": "dataArchives_tokenizer"
}
},
"tokenizer": {
"dataArchives_tokenizer": {
"type": "ngram",
"min_gram": 3,
"max_gram": 3,
"token_chars": [
"letter",
"digit"
]
}
}
}
}'
上面是设置ngram分词。
缓存
1) 清空全部缓存
curl localhost:9200/_cache/clear?pretty
{
"_shards" : {
"total" : 72,
"successful" : 72,
"failed" : 0
}
}
2) 清除单一索引缓存
curl localhost:9200/index/_cache/clear?pretty
{
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
}
}
3) 清除多索引缓存
curl localhost:9200/index1,index2,index3/_cache/clear?pretty
{
"_shards" : {
"total" : 12,
"successful" : 12,
"failed" : 0
}
}
最新评论
网飞没问题, 迪士尼+有解决方案么?
pp助手是安卓手机用的,根本下载用不来苹果
已解决
这样的话数据库里的结构为{"attachment":{"content":"xxx"}}, 要怎么才能变成{"content":"xxx"},从而使结构保持一致?
赞! make test不过的坑都写到的,谢谢楼主~
谢谢你
用了root用户还是一直502是怎么回事呢
student id 是空的