Elasticsearch基本用法

维基百科、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());

}

}

分词器

在这里插入图片描述

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值