本文参考博文:https://blog.csdn.net/qq_40694036/article/details/100217179?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522163832583416780271957604%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=163832583416780271957604&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allfirst_rank_ecpm_v1~rank_v31_ecpm-6-100217179.pc_search_result_cache&utm_term=Linux+es%E6%B7%BB%E5%8A%A0%E7%B4%A2%E5%BC%95%E5%92%8C%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84&spm=1018.2226.3001.4187
背景:
只能通过服务器直接连接,不能用postman或者其他工具,那么只能在Linux上直接新建索引,那么会用到该方法。
1、添加索引
curl -XPUT 'localhost:9200/blog' -H 'content-Type:application/json' -d '
{
"settings": {
"number_of_shards": 5,
"number_of_replicas": 0,
"analysis": {
"normalizer": {
"my_normalizer": {
"type": "custom",
"char_filter": [],
"filter": [
"lowercase",
"asciifolding"
]
}
},
"analyzer": {
"optimizeIK": {
"type": "custom",
"tokenizer": "ik_max_word",
"filter": [
"stemmer"
]
}
}
}
},
"mappings": {
"tmd": {
"dynamic": "true",
"properties": {
"indexid": {
"type": "long",
"index": true
},
"isapproved":{
"type":"boolean",
"index":true
},
"reviewer":{
"type":"keyword",
"index":true,
"normalizer": "my_normalizer"
},
"creator": {
"type": "keyword",
"index": true,
"normalizer": "my_normalizer"
},
"modifier": {
"type": "keyword",
"index": true,
"normalizer": "my_normalizer"
},
"remark": {
"type": "keyword",
"index": true,
"normalizer": "my_normalizer"
},
"note": {
"type": "keyword",
"index": true,
"normalizer": "my_normalizer"
},
"origin": {
"type": "text",
"index": true,
"analyzer": "optimizeIK",
"search_analyzer": "optimizeIK"
},
"originlower": {
"type": "keyword",
"index": true,
"normalizer": "my_normalizer"
},
"translation": {
"type": "text",
"index": true,
"analyzer": "optimizeIK",
"search_analyzer": "optimizeIK"
},
"translationlower": {
"type": "keyword",
"index": true,
"normalizer": "my_normalizer"
},
"createtime": {
"type": "long",
"index": true
},
"modifiedtime": {
"type": "long",
"index": true
}
}
}
}
}'
2、查询索引
curl -XGET localhost:9200/_cat/indices?v
此时,可以看到索引已经新建完成。