引入es并简单使用

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" }}  
      ]
    }
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值