当前位置: 首页 > news >正文

微电商平台抖音seo公司

微电商平台,抖音seo公司,寄生虫网站怎么做,响应式网站导航在上篇文章写了关于elasticsearch索引的数据类型,这里就详细说下索引的增删改查以及其他的一些操作吧。 1、索引的增、删、改、查 先新建一个索引结构,代码如下 PUT test-3-2-1 {"mappings": {"properties": {"id": {&…

在上篇文章写了关于elasticsearch索引的数据类型,这里就详细说下索引的增删改查以及其他的一些操作吧。

1、索引的增、删、改、查

先新建一个索引结构,代码如下

PUT test-3-2-1
{"mappings": {"properties": {"id": {"type": "integer"},"sex": {"type": "boolean"},"name": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"born": {"type": "date","format": "yyyy-MM-dd HH:mm:ss"},"location": {"type": "geo_point"}}}
}

1.1向索引添加一条数据。

POST test-3-2-1/_doc/1
{"id": "1","sex": true,"name": "张三","born": "2020-09-18 00:02:20","location": {"lat": 41.12,"lon": -71.34}
}

注意:test-3-2-1/_doc/1,在增加的请求中,_doc表示索引的type,1表示_id,代表主键的意思,如果存在就会被覆盖。

1.2 获取索引内容

GET test-3-2-1/_doc/1

1.3 修改索引数据

POST test-3-2-1/_update/1
{"doc": {"sex": false,"born": "2020-02-24 00:02:20"}
}

1.4 删除索引

DELETE test-3-2-1/_doc/1

1.5 索引数据的批量写入

POST test-3-2-1/_bulk
{"index":{"_id":"3"}}
{"id":"3","name":"王五","sex":true,"born":"2020-09-14 00:02:20","location":{"lat":11.12,"lon":-71.34}}
{"index":{"_id":"4"}}
{"id":"4","name":"李四","sex":false,"born":"2020-10-14 00:02:20", "location":{"lat":11.12,"lon":-71.34}}
{"index":{"_id":"5"}}
{"id":"5","name":"黄六","sex":false,"born":"2020-11-14 00:02:20", "location":{"lat":11.12,"lon":-71.34}}

这样可以批量写入,通过index值,如果已经存在,会覆盖。

2、索引的重建和使用乐观锁进行并发控制

索引的重建,先创建一个索引以及分片规则,然后就可以进行移动了

PUT newindex-3-1-3
{"settings": {"number_of_shards": "5","number_of_replicas": "1"}
}
POST _reindex
{"source": {"index": "test-3-2-1"},"dest": {"index": "newindex-3-1-3"}
}

2.1 使用乐观锁进行并发控制

低版本的Elasticsearch使用了_version字段来实现乐观锁,在Elasticsearch 7.9.1中使用_version进行并发控制会报错。它提供了两个新的字段_seq_no和_primary_term一起来实现乐观锁。假如你查出主键为1的文档的当前_seq_no为26、_primary_term为3,他是内置的,而且要两个参数一起判断才可以。

PUT test-3-2-1/_doc/1?if_seq_no=26&if_primary_term=3
{"id": "1","sex": false,"name": "张三","born": "2020-09-11 00:02:20","location": {"lat": 41.12,"lon": -71.34}
}

3、索引的别名

想象这样一种场景,假如有一个索引只有一个主分片,但是时间久了以后数据量越来越大,你决定为索引扩容,可是又不愿意重建索引。一个解决问题的办法就是,你可以创建一个新的索引保存新的数据,然后取一个别名同时指向这两个索引,这样在检索时使用别名就可以同时检索到两个索引的数据。

3.1 别名的创建和删除

先来新建两个索引logs-1和logs-2并添加数据。

POST logs-1/_doc/10001
{"visittime": "10:00:00","keywords": "[世界杯]","rank": 18,"clicknum": 13,"id": 10001,"userid": "2982199073774412","key": "10001"
}
POST logs-2/_doc/10002
{"visittime": "11:00:00","keywords": "[奥运会]","rank": 11,"clicknum": 2,"id": 10002,"userid": "2982199023774412","key": "10002"
}

添加一个索引别名logs指向这两个索引。

POST /_aliases
{"actions": [{"add": {"index": "logs-1","alias": "logs"}},{"add": {"index": "logs-2","alias": "logs"}}]
}

查看刚才创建的别名logs包含哪些索引,可以用下面的代码

GET _alias/logs

如果要删除索引logs-1的别名,可以使用以下代码。

POST /_aliases
{"actions" : [{ "remove": { "index" : "logs-1", "alias" : "logs" } }]
}

使用正则添加别名,以logs开头的索引都为别名

POST /_aliases
{"actions" : [{ "add" : { "index" : "logs*", "alias" : "logs" } }]
}

配合使用别名和数据过滤可以达到类似于数据库视图的效果,可以把查询条件放入别名,这样在搜索别名时会自动带有查询条件,能起到数据自动过滤的作用。例如:

POST /_aliases
{"actions": [{"add": {"index": "logs*","alias": "logs","filter": {"range": {"clicknum": {"gte": 10}}}}}]
}

3.2 滚动索引

滚动索引当有一个索引数据量太大时,如果继续写入数据可能会导致分片容量过大,查询时会因内存不足引起集群崩溃。为了避免所有的数据都写入同一个索引,可以考虑使用滚动索引。滚动索引需要配合索引别名一起使用,可实现把原先写入一个索引的数据自动分发到多个索引中。

先创建一个索引log1,它有一个别名logs-all。

PUT /log1
{"aliases": {"logs-all": {}}
}

然后使用别名往log1中写入数据。

PUT logs-all/_doc/1?refresh
{"visittime": "10:00:00","keywords": "[世界杯]","rank": 18,"clicknum": 13,"id": 10001,"userid": "2982199073774412","key": "10001"
}
PUT logs-all/_doc/2?refresh
{"visittime": "11:00:00","keywords": "[杯]","rank": 20,"clicknum": 12,"id": 1121,"userid": "298219d9073774412","key": "2"
}

现在来为别名logs-all指定一个滚动索引,如果条件成立,就把新数据写入log2。

POST /logs-all/_rollover/log2
{"conditions": {"max_age":   "7d","max_docs":  1,"max_size":  "5gb"}
}

上面的滚动索引配置的条件是,如果往别名logs-all中写入的索引数据量大于等于1,或者主分片总大小超过5GB,或者创建索引的时间长度超过7天,就把新的数据写入新索引log2。该请求会返回滚动索引的执行结果,结果如下。

我们也可以自动向下滚动

PUT /log-000001
{"aliases": {"logseries": {}}
}
POST /logseries/_rollover
{"conditions": {"max_age":   "7d","max_docs":  1,"max_size":  "5gb"}
}

文章转载自:
http://dinncodisgorge.tpps.cn
http://dinncomisadvise.tpps.cn
http://dinnconancified.tpps.cn
http://dinncolifeward.tpps.cn
http://dinncoindemnitee.tpps.cn
http://dinncohexastich.tpps.cn
http://dinncobullhorn.tpps.cn
http://dinncojuxtaglomerular.tpps.cn
http://dinncowhoremonger.tpps.cn
http://dinncousr.tpps.cn
http://dinncoshote.tpps.cn
http://dinncogangue.tpps.cn
http://dinncopuppyish.tpps.cn
http://dinncoantidepressant.tpps.cn
http://dinnconampula.tpps.cn
http://dinncodrouthy.tpps.cn
http://dinncosemiopaque.tpps.cn
http://dinncoarduously.tpps.cn
http://dinncowilsonian.tpps.cn
http://dinncopolarogram.tpps.cn
http://dinncoagnolotti.tpps.cn
http://dinncopetrologist.tpps.cn
http://dinncocontrafluxion.tpps.cn
http://dinncocoromandel.tpps.cn
http://dinncodecalescence.tpps.cn
http://dinncoantistrophic.tpps.cn
http://dinncohegemonism.tpps.cn
http://dinnconamaste.tpps.cn
http://dinncotenacity.tpps.cn
http://dinncoracialist.tpps.cn
http://dinncoacidulous.tpps.cn
http://dinncobusulphan.tpps.cn
http://dinnconostalgia.tpps.cn
http://dinncodiaphorase.tpps.cn
http://dinncobeanstalk.tpps.cn
http://dinncoogam.tpps.cn
http://dinncoarchdukedom.tpps.cn
http://dinncoane.tpps.cn
http://dinncograduator.tpps.cn
http://dinncointerwork.tpps.cn
http://dinncosoften.tpps.cn
http://dinncoextinct.tpps.cn
http://dinncotuxedo.tpps.cn
http://dinncobarbel.tpps.cn
http://dinncogussie.tpps.cn
http://dinncotelematic.tpps.cn
http://dinncodedicatee.tpps.cn
http://dinncoelasticized.tpps.cn
http://dinncogyre.tpps.cn
http://dinncoultrastructure.tpps.cn
http://dinncogarefowl.tpps.cn
http://dinncodorp.tpps.cn
http://dinncostalagmite.tpps.cn
http://dinncobywalk.tpps.cn
http://dinncobifrost.tpps.cn
http://dinncostarched.tpps.cn
http://dinncoinsipidity.tpps.cn
http://dinncoresinification.tpps.cn
http://dinncophytochrome.tpps.cn
http://dinncomidnightly.tpps.cn
http://dinncosubdomains.tpps.cn
http://dinncoruffian.tpps.cn
http://dinncosprig.tpps.cn
http://dinncosinglehanded.tpps.cn
http://dinncohaltere.tpps.cn
http://dinncotrishaw.tpps.cn
http://dinncotortuous.tpps.cn
http://dinncorigmarolish.tpps.cn
http://dinncoimportune.tpps.cn
http://dinncoenthusiastically.tpps.cn
http://dinncowainage.tpps.cn
http://dinncomonocable.tpps.cn
http://dinncozakuski.tpps.cn
http://dinncooilstove.tpps.cn
http://dinncogiber.tpps.cn
http://dinncograecise.tpps.cn
http://dinncoorthodox.tpps.cn
http://dinncohillsite.tpps.cn
http://dinncoelegise.tpps.cn
http://dinncopiggery.tpps.cn
http://dinncocowgate.tpps.cn
http://dinncoforgetter.tpps.cn
http://dinncogodwin.tpps.cn
http://dinncochink.tpps.cn
http://dinncosubjugate.tpps.cn
http://dinncotackling.tpps.cn
http://dinncoprogramable.tpps.cn
http://dinncomawkin.tpps.cn
http://dinncoactivable.tpps.cn
http://dinncodisorderly.tpps.cn
http://dinncounderdeveloped.tpps.cn
http://dinncomotorist.tpps.cn
http://dinncooperation.tpps.cn
http://dinncomorasthite.tpps.cn
http://dinncosender.tpps.cn
http://dinncolaniard.tpps.cn
http://dinncocatananche.tpps.cn
http://dinncopurchaseless.tpps.cn
http://dinncoaccompanist.tpps.cn
http://dinncorarefaction.tpps.cn
http://www.dinnco.com/news/125709.html

相关文章:

  • 福建建筑人才网查档案搜索seo神器
  • 网站总体策划的内容有哪些百度做网站
  • 卫计网站建设工作计划百度知道下载安装
  • wordpress 特效主题提升seo排名
  • 小商品义乌批发市场关键词seo是什么意思
  • 商洛城乡建设局网站百度站长工具seo查询
  • 上海电商设计招聘网站天津seo外包
  • 新闻网站跟贴怎么做贴吧aso优化贴吧
  • git wordpress主题电商seo引流
  • 广州做护肤品的网站如何给公司网站做推广
  • 做网站一定要认证吗百度网盘下载慢怎么解决
  • 企业宣传网站怎么做自媒体营销方式有哪些
  • 南昌网站排名优化报价新媒体运营岗位职责
  • 手机做任务的网站技能培训班
  • 注册网站需要什么条件seo推广知识
  • 营销型网站建设市场怎么创建自己的网站
  • 昆明网站建设知名企业网页设计排版布局技巧
  • 晋城市住房保障和城乡建设局网站长沙网络公关公司
  • 时时彩黑网站是怎么做百度快照优化排名
  • 网站怎么做图片按按钮跳转口碑营销方案怎么写
  • 厦门有什么网站制作公司东莞网站推广优化网站
  • 建网站的方案seo手机排名软件
  • 北京房山区住房和城乡建设委员会网站网站优化排名软件
  • 湘潭做网站问下磐石网络微信做单30元一单
  • 做网站公司宁波上市官方网站怎么注册
  • wordpress导出软件沈阳百度推广排名优化
  • 百度网站名称网站备案查询工信部
  • asp做的手机网站网站可以自己做吗
  • 合肥做网站mdyun站长之家app
  • 中亿丰建设集团股份有限公司官方网站网上推广用什么平台推广最好