维基百科、GitHub-站内实时搜索
网址:
https://www.elastic.co/cn/products/elasticsearch
概述:
Elasticsearch 是一个分布式、RESTful 风格的搜索和数据分析引擎,能够解决不断涌现出的各种用例。作为 Elastic Stack 的核心,它集中存储您的数据,帮助您发现意料之中以及意料之外的情况
应用场景:
1)海量数据分析引擎
2)站内搜索引擎
3)数据仓库
版本
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.0.0-linux-x86_64.tar.gz
启动
非root用户
报错:Caused by: java.lang.RuntimeException: can not run elasticsearch as root
启动命令;
-> elasticsearch &
插件
GitHub上搜索 elasticsearch_head找到mobz下的
wget https://github.com/mobz/elasticsearch-head.git
进入到elasticsearch-head-master
检查版本 node -v
v10.1.0
安装npm
npm install
启动
npm run start
浏览器打开http://localhost:9100
启动报错:
1)需要非root用户启动
2): max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
解决方案:修改配置文件/etc/security/limits.conf
3) max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决方案:
修改**/etc/sysctl.conf**文件,增加配置vm.max_map_count=262144
4)删除data下的数据
集群搭建
基础概念
索引
分片
备份
创建索引
非结构化索引:如果mapping为null
# 结构化索引创建
第三方工具postman
下载-》安装-.>注册
输入与搭建的环境的IP和端口一致就可以连接
类型
索引:相当于数据库database
type;相当于表table
1:表的id
直接修改参数
脚本方式修改
修改结果:
高级查询
kinaba对elasticsearch的应用
错误:Ijava.lang.IllegalStateException: Unsupported transport.type [netty4]
pom依赖版本不匹配
http://www.cnblogs.com/softidea/p/6080086.html#
API
创建索引
@Before建立连接
public void init() throws Exception{
Settings elasticsearch = Settings.builder().put("cluster.name", "elasticsearch").build();
client = new PreBuiltTransportClient(elasticsearch);
client.addTransportAddress(new TransportAddress(InetAddress.getByName("192.168.8.xxx"),9300));
}
# 创建索引
@Test
public void create(){
//create index
client.admin().indices().prepareCreate("blog4").get();
//close
client.close();
}
删除索引
@Test
public void drop(){
client.admin().indices().prepareDelete("book").get();
client.close();
}
插入数据
@Test
public void createType(){
HashMap<String, Object> hp = new HashMap<String, Object>();
hp.put("id",2);
hp.put("title","my first esasticseach program");
hp.put("content","我的第一个程序");
IndexResponse indexResponse = client.prepareIndex("helloec", "hello", "2").setSource(hp).execute().actionGet();
System.out.println("Index : "+indexResponse.getIndex());
System.out.println("type : "+indexResponse.getType());
System.out.println("content : "+indexResponse.getResult());
}
查询语句
@Test
public void queryall(){
SearchResponse response = client.prepareSearch("helloec")
.setTypes("hello")
.setQuery(QueryBuilders.wildcardQuery("title", "my"))
.get();
SearchHits hits = response.getHits();
System.out.println(hits.getTotalHits());
for(SearchHit hit : hits){
System.out.println(hit.getSourceAsString());
}
}