ElasticSearch(一)

ElasticSearch 介绍
1.elasticsearchh的概述:
	ElasticSearch是一款基于lucene开发的全文检索服务器;Elasticsearch仅支持json文件格式;支持Restful风格;默认端口号9200
	PUT:增	 DELETE:删	POST:改 	GET:查	
	
2.elasticsearch的使用:
第一步:启动elasticseach服务器
elasticsearch-5.6.8/bin/elasticsearch.bat
第二步:启动elasticseach图形化界面插件,默认端口号9100
cmd-->进入elasticsearch-head-master目录-->grunt server

3.elasticsearch类比于database:
Relational DB ‐> Databases ‐> Tables ‐> Rows ‐> Columns
Elasticsearch ‐> Indices   ‐> Types  ‐> Documents ‐> Fields
Restful接口访问
1.创建索引index和映射mapping
url: http:localhost:9200/blog		//blog对应索引库名称,put请求
{
"mappings":{		//mappings是对处理数据的方式和规则做一些限制
   "hello":{			//hello对应类型type
    "properties":{			
            "id":{
                "type":"long",	
                "store":true,
                "index":false	
            },
            "title":{
                "type":"text",
                "store":true,
                "index":true,
                "analyzer":"ik_smart"
            },
            "content":{
                "type":"text",
                "store":true,
                "index":true,
                "analyzer":"ik_smart"
            }
        }
    }
}	
}
	"index"的另外一种取值方式: analyzed分词且索引  not_analyzed不分词  no不索引
2.创建索引后修改mapping
url: http:localhost:9200/blog/hello/_mapping		//hello对应type的名称,post请求
{
	"hello":{
		"properties":{
            "id":{
			"type":"long",
			"store":true
            },
			"title":{
			"type":"text",
			"store":true,
			"index":true,
			"analyzer":"ik_smart"
            }		
		}
	}
}

3.删除索引index
url: http:localhost:9200/blog		//delete请求

4.创建文档document,一个document相当于表中的一条记录
url: http:localhost:9200/blog/hello/1	//post请求
"/1"是文档的真实id,对应的字段是"_id";如果省略,elasticsearch会自动随机生成一个"_id";通常我们会手动指定一个"_id"并与"id"保持一致
{
	"id":"1",
	"title":"测试title",
	"content":"测试content"
}

5.修改文档document,同创建document,elasticsearch会先根据id直接先删除之前的document,再创建docuemnt
6.删除document
url: http:localhost:9200/blog/hello/1		//delete请求
7.查询文档-根据id查询
url: http:localhost:9200/blog/hello/1		//get请求
8.查询文档-querystring查询(QueryParser)
url: http:localhost:9200/blog/hello/_search		//post请求
{
	"query":{
        "query_string":{
            "default_field":"title",
            "query":"搜索服务器"	
        }
	}
}
9.查询文档-term查询(TermQuery)
url: http:localhost:9200/blog/hello/_search		//post请求
{
    "query":{
        "term":{
            "title":"搜索服务器"
        }
    }
}
IKAnalyzer
分词:我是程序员
ik_smart 最少化切分		我/是/程序员
ik_max_word 最细粒度划分  	我/是/程序员/程序/员
Cluster集群
1.集群cluster	
	一个集群就是由一个或多个节点组织在一起,每个节点各持有整个集群的部分数据,由所有节点组织在一起,共同提供索引和搜索功能。集群的默认标识名字是"elasticsearch",通过集群的唯一标识来指定多个节点加入这个集群
2.节点node
	一个节点就是集群中的一个服务器
3.分片shard和复制replicas
	将索引划分为多份,每个分片都对应一个复制(副本),一个节点下包含多个分片,默认分片数为5,通常分片会跟复制存储在不同的节点下
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值