es 7.13.0使用

docker pull elasticsearch:7.13.0

docker network create elastic

docker run --name elasticsearch --net elastic -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -t elasticsearch:7.13.0

好像不带ik的分词,所以还需要安装下

docker exec -it elasticsearch /bin/bash

wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.13.0/elasticsearch-analysis-ik-7.13.0.zip

unzip 下载的文件
rm –rf *.zip
mv elasticsearch/ /usr/share/elasticsearch/plugins/ik

可以确认是否安装好了分词器

cd /usr/share/elasticsearch/bin
elasticsearch-plugin list

即可列出系统的分词器

然后重启elasticsearch

docker restart elasticsearch
参考:https://cloud.tencent.com/developer/article/2139072



 

然后就可以创建mapping了

curl -X PUT 'http://localhost:9200/chunk' -H "Content-Type: application/json" -d '
{
 "settings": {
    "analysis": {
      "analyzer": {
        "my_analyzer": {
          "type": "custom",
          "tokenizer": "ik_max_word"
        }
      }
    }
  },
  "mappings": {
      "properties": {
        "recall_content_term": {
          "type": "text",
          "analyzer":"whitespace"
        },
        "recall_content": {
          "type": "text",
          "analyzer":"my_analyzer"
        },
	   "doc_term_hold":{
	      "type": "text"
        },
	   "title":{
	      "type": "text"
        },
	   "desc":{
	      "type": "text"
        },
	   "channel":{
	      "type": "text"
        },
        "id": {
          "type": "text"
        }
      }
  }
}'

  


 

 然后就是建立索引

 

send_es_url="http://localhost:9200/chunk/_doc/"

 

send_data = dict({"id":ids,"channel":chn_id,"recall_content":content,"doc_term_hold":"test","recall_content_term":"test","title":title,"desc":desc})

ret = post_result_from_url(send_es_url+ids, send_data)

注意url需要拼上ids建立索引


 

最后就是查询索引

http://localhost:9200/chunk/_search

 

{"query":{"match":{"recall_content":"SDFSF"}},"size":100}

posted @ 2024-01-16 14:27  dmesg  阅读(8)  评论(0编辑  收藏  举报