1 删除旧索引
curl -XDELETE -u 用户名:密码 http://ip:8200/metadata
delete /metadata
2 创建索引
curl -XPOST "http://IP:8200/metadata"
返回 :{"acknowledged":true}
3 设置分词器
curl -u 用户名:密码 -H "Content-Type: application/json" -X PUT 'http://ip:8200/metadata/' -d '
{
"settings": {
"index": {
"analysis": {
"analyzer": {
"nlp_phrase": {
"tokenizer":"bd-nlp-phrase"
},
"nlp_basic": {
"tokenizer":"bd-nlp-basic"
},
"synonym_nlp_phrase": {
"type": "custom",
"tokenizer":"bd-nlp-phrase",
"filter": ["synonym_filter"]
},
"synonym_nlp_basic": {
"type": "custom",
"tokenizer":"bd-nlp-basic",
"filter": ["synonym_filter"]
},
"pinyin_analyzer_ik_smart":{
"type": "custom",
"tokenizer": "ik_smart"
},
"pinyin_analyzer_ik_max_word": {
"type": "custom",
"tokenizer": "ik_max_word"
},
"pinyin_analyzer_npl_basic": {
"type": "custom",
"tokenizer": "bd-nlp-basic"
},
"pinyin_analyzer_npl_phrase": {
"type": "custom",
"tokenizer": "bd-nlp-phrase"
},
"synonym_filter_ik_smart": {
"type": "custom",
"tokenizer": "ik_smart"
},
"synonym_filter_ik_max_word": {
"type": "custom",
"tokenizer": "ik_max_word"
}
},
"filter": {
"synonym_filter": {
"type": "bd_synonym",
"expand": true,
"synonyms_path": "http://10.138.4.125/synonym.txt",
"reload_interval": 30
}
}
}
}
}
}'
4 设置mapping
curl -u 用户名:密码 -H "Content-Type: application/json" -X POST 'http://ip:8200/metadata/_mapping' -d '
{"properties" : {
"accessTime" : {
"type" : "long"
},
"age" : {
"type" : "integer"
},
"businessLine" : {
"type" : "keyword"
},
"createTime" : {
"type" : "long"
},
"created" : {
"type" : "date"
},
"dataSource" : {
"type" : "keyword"
},
"database" : {
"type" : "keyword"
},
"databaseName" : {
"type" : "keyword"
},
"describe" : {
"type": "text",
"analyzer": "synonym_nlp_basic"
},
"detail" : {
"type": "text",
"analyzer": "synonym_nlp_basic"
},
"docId" : {
"type" : "keyword"
},
"encryptionLevels" : {
"type" : "keyword"
},
"fieldChineseName" : {
"type": "text",
"analyzer": "synonym_nlp_basic"
},
"fieldName" : {
"type": "text",
"analyzer": "ik_max_word"
},
"fieldType" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"firstClass" : {
"type" : "keyword"
},
"isPrimarykey" : {
"type" : "keyword"
},
"name" : {
"type" : "text"
},
"secondClass" : {
"type" : "keyword"
},
"state" : {
"type" : "keyword"
},
"tableChineseName" : {
"type": "text",
"analyzer": "synonym_nlp_basic"
},
"tableName" : {
"type": "text",
"analyzer": "ik_max_word"
},
"tableResponsible" : {
"type": "text",
"analyzer": "synonym_nlp_basic"
},
"theme" : {
"type": "text",
"analyzer": "synonym_nlp_basic"
},
"title" : {
"type": "text",
"analyzer": "synonym_nlp_basic"
},
"type" : {
"type" : "keyword"
},
"updateTime" : {
"type" : "long"
},
"users" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}}'
5 设置最大查询数。
PUT /metadata/_settings
{
"index.max_result_window":"2147483647"
}
6 验证
GET /metadata/_settings
7 常用命令
GET /metadata/_search
{
"query": {
"bool": {
"must": [
{ "match": { "databaseName" : "GP" }},
{ "match": { "type" : "isTable" }}
]
}
}
}