1、下载elasticsearch
https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.6.2-windows-x86_64.zip
2、修改配置
./config/elasticsearch.yml
…
跨域问题配置在文件的末尾添加如下内容:
http.cors.enabled: true
http.cors.allow-origin: “*”
3、
下载head
https://codeload.github.com/mobz/elasticsearch-head/zip/master
4、安装head
到head解压目录
npm install -g grunt-cli
npm install
5、运行head
到head解压目录
npm run start
6、运行elasticsearch
到elasticsearch/bin目录
运行 .\elasticsearch.bat
7、postman 提交
建立索引put方法:
http://localhost:9200/index
{
"mappings":{
"properties":{
"id":{"type":"long"},
"name":{"type":"text"},
"text":{"type":"text"}
}
}
}
http://localhost:9200/index/_mapping
"properties":{
"id":{"type":"long"},
"name":{"type":"text"},
"text":{"type":"text"}
}
提交数据put/post方法
http://localhost:9200/index/_doc/1
{
"id":"1",
"name":"测试1",
"text":"我这个不知道怎么回事,直接是中文的,是根据地区IP默认识别安装的。所以其他功能我不讲了,我就直说一下看索引(index)的 Mapping 在哪看。"
}
8、中文分词
.\elasticsearch-plugin install analysis-smartcn
http://localhost:9200/_analyze
post提交
{
"analyzer":"smartcn",
"text":"火箭明年总冠军"
}
9、ik中文分词
https://github.com/medcl/elasticsearch-analysis-ik/releases
Es目录中不要包含空格
解压放到 ./plugins目录下
{
"analyzer":"ik_max_word",
"text":"火箭明年总冠军"
}
10、批量导入数据
在kibana中建立索引对象
PUT /shakespeare
{
"mappings":{
"properties":{
"type":{"type":"keyword"},
"line_number":{"type":"keyword"},
"text_entry":{"type":"keyword"},
"speaker": {"type": "keyword"},
"play_name": {"type": "keyword"},
"line_id": {"type": "integer"},
"speech_number": {"type": "integer"}
}
}
}
在cmd命令窗口执行:
去官网下载测试数据
https://download.elastic.co/demos/kibana/gettingstarted/logs.jsonl.gz
https://download.elastic.co/demos/kibana/gettingstarted/accounts.zip
https://download.elastic.co/demos/kibana/gettingstarted/shakespeare_6.0.json
curl -H "Content-Type: application/json" -X POST "localhost:9200/shakespeare/_doc/_bulk?pretty" --data-binary "@shakespeare.json"
相关参考:
https://blog.youkuaiyun.com/qq_36571506/article/details/113882669
java.lang.IllegalArgumentException: Plugin [analysis-pinyin] was built for Elasticsearch version 8.2.1
版本不一致
修改:
在改分词器文件夹下找到plugin-descriptor.properties
#elasticsearch.version=改成你当前服务器es的版本
elasticsearch.version=8.2.1