随笔分类 - ElasticSearch
摘要:1、手动指定 使用put:put /index/type/66 通常是把其它系统的已有数据导入到es时。 2、由es生成id值 使用post:post /index/type es生成的id长度为20个字符,使用的是base64编码。URL安全,使用的是GUID算法,分布式下并发生成id值时不会冲突
阅读全文
摘要:文档的核心元数据包括三个:索引、类型、id 1、_index 说明了一个文档存储在哪个索引中,同一个索引下存放的是相似的文档(文档的field多数是相同的)索引名必须是小写的,不能以下划线开头,不能包括逗号。 2、_type 表示文档属于索引中的哪个类型,一个索引下只能有一个type,类型名可以是大
阅读全文
摘要:ElasticSearch的容错机制处理过程 以9个shard,3个节点为例,如果master节点宕机,此时不是所有的primary shard都是Active status,所以此时的集群状态是red。 容错处理的第一步:重新选举一台服务器作为master 容错处理的第二步:新选举的master会
阅读全文
摘要:水平扩容的过程 1、扩容后primary shard和replica shard会自动的负载均衡 2、扩容后每个节点的shard会减少,那么分配给每个shard的cpu,内存、io资源会更多,性能提高 3、扩容的极限,如果有6个shard,扩容的极限就是6个节点,每个节点上一个shard,如果想超出
阅读全文
摘要:两个节点环境下创建索引分析 将3个primary shard分配到一个node上去,另外3个replica shard分配到另外一个节点上 primary shard 和 replica shard保持同步 primary shard 和 replica shard都可以处理客户端的读请求 prim
阅读全文
摘要:1、分片和副本机制 1、index包含多个shard 2、每个shard都是一个最小工作单元,承担部分数据;每个shard都是一个lucene示例,有完整的建立索引和处理请求的能力 3、增减节点时,shard会自动在nodes中负载均衡 4、primary shard和replica shard,每
阅读全文
摘要:1、分布式架构的透明隐藏特性 ElasticSearch是一个分布式架构系统,隐藏了复杂的处理机制。 分片机制:我们不用关系数据是按照什么机制分片的,最后放入到哪个分片中。 集群发现机制(cluster discovery):比如当前我们启动了一个es进程,当启动了第二个es进程时,这个进程作为一个
阅读全文
摘要:在实际应用当中,有时候搜索条件复杂,我们可以使用复合查询,也叫组合查询。可以使用bool查询。 1、使用bool查询 接收以下参数: must:文档必须匹配这些条件才能被包含进来。 must_not:文档必须不匹配这些条件才能被包含进来。 should:如果满足这些语句中的任意语句,将增加_scor
阅读全文
摘要:下面的代码展示了如何获取集群信息和索引信息 @Test public void testCluster() throws IOException, InterruptedException, ExecutionException { //指定集群 Settings settings = Settin
阅读全文
摘要:1、按年龄分组,查询每组的个数 @Test public void testTerms() throws IOException, InterruptedException, ExecutionException { //指定集群 Settings settings = Settings.build
阅读全文
摘要:查询interests字段包含changge并且不包含lvyou,或者address字段包含bei jing的文档,并且前面两种都要满足birthday>="1980-01-01" @Test public void testBoolQuery() throws IOException, Inter
阅读全文
摘要:1、查询所有字段中含有changge且不含有hejiu的文档 @Test public void testQueryStringQuery() throws IOException, InterruptedException, ExecutionException { //指定集群 Settings
阅读全文
摘要:1、求索引lib3下的age字段的最大值 @Test public void testAggMax() throws IOException, InterruptedException, ExecutionException { //指定集群 Settings settings = Settings
阅读全文
摘要:1、查询index1中content字段包含工厂的文档 @Test public void testMatch() throws IOException, InterruptedException, ExecutionException { //指定集群 Settings settings = Se
阅读全文
摘要:1、删除index1中,title包含工厂的文档 @Test public void testQueryDelete() throws IOException, InterruptedException, ExecutionException { //指定集群 Settings settings =
阅读全文
摘要:1、查询索引是index1,类型是blog,id是8、10和索引是lib3,类型是user,id是1、2、3的文档 @Test public void testMultiGet() throws IOException, InterruptedException, ExecutionExceptio
阅读全文
摘要:新建索引,名称index1、类型blog、title与content用中文分词器 PUT /index1 { "settings": { "number_of_shards": 3, "number_of_replicas": 0 }, "mappings": { "blog":{ "propert
阅读全文
摘要:1、添加elasticsearch客户端依赖 <dependency> <groupId>org.elasticsearch.client</groupId> <artifactId>transport</artifactId> <version>6.2.4</version> </dependen
阅读全文
摘要:1、准备数据 POST /lib/items/_bulk {"index":{"_id":1}} {"price":40,"itemID":"ID100123"} {"index":{"_id":2}} {"price":50,"itemID":"ID100124"} {"index":{"_id"
阅读全文
摘要:filter是不计算相关性的,同时可以cache,因此,filter速度要快于query 1、准备数据 POST /lib/items/_bulk {"index":{"_id":1}} {"price":40,"itemID":"ID100123"} {"index":{"_id":2}} {"p
阅读全文
浙公网安备 33010602011771号