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

网站建设js网站免费建站

网站建设js,网站免费建站,广东上海专业网站建设公司,可在哪些网站做链接06_ElasticSearch:索引和文档的CURD 索引的CURD新增查询修改删除 文档crud新增查询改删除批量操作 Bulk API 索引的CURD 新增 # 创建索引名为 tehero_index 的索引 PUT /tehero_index?pretty { # 索引设置"settings": {"index": {"numb…

06_ElasticSearch:索引和文档的CURD

  • 索引的CURD
    • 新增
    • 查询
    • 修改
    • 删除
  • 文档crud
    • 新增
    • 查询
    • 删除
    • 批量操作 Bulk API

索引的CURD

新增

# 创建索引名为 tehero_index 的索引
PUT /tehero_index?pretty
{
# 索引设置"settings": {"index": {"number_of_shards": 1, # 分片数量设置为1,默认为5"number_of_replicas": 1 # 副本数量设置为1,默认为1}},
# 映射配置"mappings": {"_doc": { # 类型名, 7 版本不允许设置"dynamic": false, # 动态映射配置
# 字段属性配置"properties": {"id": {"type": "integer"  # 表示字段id,类型为integer},"name": {"type": "text","analyzer": "ik_max_word", # 存储时的分词器"search_analyzer": "ik_smart"  # 查询时的分词器},"createAt": {"type": "date"}}}}
}

注:dynamic:是动态映射的开关,有3种状态:true 动态添加新的字段–缺省;推荐使用)false 忽略新的字段,不会添加字段映射,但是会存在于_source中;(strict 如果遇到新字段抛出异常;

查询

GET /tehero_index  # 索引名,可以同时检索多个索引或所有索引
如:GET /*    GET /tehero_index,other_indexGET /_cat/indices?v  #查看所有 index

修改

ES提供了一系列对index修改的语句,包括副本数量的修改、新增字段、refresh_interval值的修改、索引分析器的修改(后面重点讲解)、别名的修改

# 修改副本数
PUT /tehero_index/_settings
{"index" : {"number_of_replicas" : 2}
}# 修改分片刷新时间,默认为1s
PUT /tehero_index/_settings
{"index" : {"refresh_interval" : "2s"}
}# 新增字段 age
PUT /tehero_index/_mapping/_doc
{"properties": {"age": {"type": "integer"}}
}

删除

# 删除索引
DELETE /tehero_index
# 验证索引是否存在
HEAD tehero_index
返回:404 - Not Found

文档crud

新增

# 新增单条数据,并指定es的id 为 1
PUT /tehero_index/_doc/1?pretty
{"name": "Te Hero"
}
# 新增单条数据,使用ES自动生成id
POST /tehero_index/_doc?pretty
{"name": "Te Hero2"
}# 使用 op_type 属性,强制执行某种操作
PUT tehero_index/_doc/1?op_type=create
{"name": "Te Hero3"
}
注意:op_type=create强制执行时,若id已存在,ES会报“version_conflict_engine_exception”。
op_type 属性在实践中同步数据时是有用的,后面讲解数据库与ES的数据同步问题时,TeHero再为大家详细讲解。

查询

我们查询数据,看下效果:GET /tehero_index/_doc/_search

# 根据id,修改单条数据
(ps:修改语句和新增语句相同,可以理解为根据ID,存在则更新;不存在则新增)
PUT /tehero_index/_doc/1?pretty
{"name": "Te Hero-update"
}# 根据查询条件id=10,修改name="更新后的name"(版本冲突而不会导致_update_by_query 中止)
POST tehero_index/_update_by_query
{"script": {"source": "ctx._source.name = params.name","lang": "painless","params":{"name":"更新后的name"}},"query": {"term": {"id": "10"}}
}

删除

# 1、根据id,删除单个数据
DELETE /tehero_index/_doc/1# 2、delete by query
POST tehero_index/_delete_by_query
{"query": {"match": {"name": "2"}}
}

批量操作 Bulk API

# 批量操作
POST _bulk
{ "index" : { "_index" : "tehero_test1", "_type" : "_doc", "_id" : "1" } }
{ "this_is_field1" : "this_is_index_value" }
{ "delete" : { "_index" : "tehero_test1", "_type" : "_doc", "_id" : "2" } }
{ "create" : { "_index" : "tehero_test1", "_type" : "_doc", "_id" : "3" } }
{ "this_is_field3" : "this_is_create_value" }
{ "update" : {"_id" : "1", "_type" : "_doc", "_index" : "tehero_test1"} }
{ "doc" : {"this_is_field2" : "this_is_update_value"} }# 查询所有数据
GET /tehero_test1/_doc/_search
结果:
{"took": 33,"timed_out": false,"_shards": {"total": 5,"successful": 5,"skipped": 0,"failed": 0},"hits": {"total": 2,"max_score": 1,"hits": [{"_index": "tehero_test1","_type": "_doc","_id": "1","_score": 1,"_source": {"this_is_field1": "this_is_index_value","this_is_field2": "this_is_update_value"}},{"_index": "tehero_test1","_type": "_doc","_id": "3","_score": 1,"_source": {"this_is_field3": "this_is_create_value"}}]}
}

注:POST _bulk 都做了哪些操作呢?

1、若索引“tehero_test1”不存在,则创建一个名为“tehero_test1”的 index,同时若id = 1 的文档存在,则更新;不存在则插入一条 id=1 的文档;

2、删除 id=2 的文档;

3、插入 id=3 的文档;若文档已存在,则报异常;

4、更新 id = 1 的文档。

ps:批量操作在实践中使用是比较多的,因为减少了IO,提高了效率!

http://www.dtcms.com/wzjs/804550.html

相关文章:

  • 西安装修公司网站制作巨量关键词搜索查询
  • 虚拟主机搭建网站网站建设价格专注制作网站设计
  • 内蒙古做网站的公司广东建设局网站
  • 网站运营是做什么的wordpress后台登陆美化
  • 网站开发软件开发怎么样图案设计网站有哪些
  • 苏州网络营销推广软件运营淄博优化网站排名
  • 做自适应网站对设计稿的要求wordpress远程安装教程视频
  • 中国石油工程建设有限公司网站北京网站设计首选 新鸿儒
  • 江苏手机网站建设公司有限责任公司的优缺点
  • 学做网站理财网站方案建设
  • 建站服务搭建的页面时专门做资产负债表结构分析的网站
  • 工作网站建设平面设计的创意手法有哪些
  • dw制作简单网站模板下载地址如何创建一个网页
  • 有没有兼职做设计的网站吗wordpress文章站
  • 阜宁做网站价格高端网站建设制作
  • h5网站做微信公众号广州哪个网站建设公司好
  • 响应式网站开发教程pdf家具定制
  • 网站运营和维护网页设计需要学什么代码
  • 网站建设理由wordpress过滤敏感
  • 枞阳县住房和城乡建设局网站金泉网网站建设
  • 石家庄网站制作官网辽宁建设厅新网站
  • 移动端漂亮网站wordpress源代码插件
  • 什么是门户网站有哪些公司网站内容更新怎么做
  • 免费推广网站怎么做网站建设规划书摘要500字
  • 深圳 电子政务网站建设方案深圳新闻
  • 企业网站怎么做的更好个人网站可以做经营性的吗
  • 公司网站一年多少钱创意设计人才网
  • 个人网站设计界面网站用户体验比较
  • 河北企业建网站58同城通辽做网站
  • 自己怎么手机做网站wordpress添加邮件输入列表