# Elasticsearch and Kibana Setup with IK Plugin ## 目录 1. [版本](#版本) 2. [Docker创建注意](#Docker创建注意) 3. [Linux创建注意](#Linux创建注意) 4. [检查服务](#检查服务) 5. [创建索引](#创建索引) - [创建索引脚本](#创建索引脚本) - [查询索引结构](#查询索引结构) - [查询总数](#查询总数) 6. [查询语句](#查询语句) - [查询CompanyName](#查询CompanyName) - [查询ProductFactoryCode](#查询ProductFactoryCode) - [规则三-转码查询](#规则三-转码查询) - [规则四-转码查询](#规则四-转码查询) 7. [分词解析预测](#分词解析预测) ## 版本 - Elasticsearch: `7.12.1` - Kibana: `7.12.1` (if needed) - IK Plugin: `7.12.1` - ## Docker创建注意 docker创建服务需要注意网关设置 ```dockerfile docker run -d --name es -e "ES_JAVA_OPTS=-Xms512m -Xmx512m" -e "discovery.type=single-node" --privileged --net esnet -p 9200:9200 -p 9300:9300 elasticsearch:7.12.1 docker run -d --name kibana -e ELASTICSEARCH_HOSTS=http://es:9200 --net esnet -p 5601:5601 kibana:7.12.1 ``` ## Linux创建注意 linux创建服务需要注意 参考:[this guide](https://blog.csdn.net/m0_50287279/article/details/131819482). ## 检查服务 可以获取当前服务器是否创建好 ```sh curl 127.0.0.1:9200 ``` linux安装要确认好是否提供外部服务 --- ik分词安装注意事项 与es版本对齐,在对应的文件夹plugins创建ik文件夹,然后上传zip,解压即可; --- ## 创建索引 ### 创建索引脚本 ```sh PUT /udi/ { "mappings": { "properties": { "id": { "type": "long" }, "companyName": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" }, "productFactoryCode": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" }, "brandName": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" }, "productName": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" }, "specification": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" }, "model": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart" } } } } ``` ### 查询索引结构 ```sh GET /udi/_mapping ``` ### 查询总数 ```sh GET /udi/_count ``` --- ## 查询语句 ### 查询CompanyName ```sh POST /udi/_search { "query": { "match": { "companyName": "" } } } ``` ### 查询ProductFactoryCode ```sh POST /udi/_search { "query": { "match": { "productFactoryCode": "" } } } ``` ### 规则三-转码查询 ```sh POST /udi/_search { "query": { "bool": { "should": [ { "match": { "companyName": "大博医疗" } }, { "term": { "companyName": "大博医疗" } }, { "match": { "productFactoryCode": "09A221013" } }, { "term": { "productFactoryCode": "09A221013" } } ] } }, "_source": ["companyName","productFactoryCode"] } ``` ### 规则四-转码查询 ```sh POST /udi/_search { "query": { "bool": { "should": [ { "match": { "productName": "/" } }, { "match": { "brandName": "大博医疗" } }, { "match": { "specification": "RHQ11" } }, { "match": { "model": "RHQ11" } } ] } }, "_source": ["productName","brandName","specification","model"] } ``` ### 分词解析预测 ```sh POST _analyze { "analyzer": "ik_smart", "text": ["大博医疗"] } ```