欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

elasticsearch基本索引和CRUD操作、bulk批量操作

程序员文章站 2022-03-16 22:56:07
ELK包括ElasticSearch(数据存储、快速查询)、logstash(日志搜集)、kibana(展示ElasticSearch数据的图形界面)。4种常用的HTTP请求方法:POST /uri 创建DELETE /uri/xxx 删除PUT /uri/xxx 更新或创建GET /uri/xxx 查看CRUD操作示例:PUT test{ "settings":......

ELK包括ElasticSearch(数据存储、快速查询)、logstash(日志搜集)、kibana(展示ElasticSearch数据的图形界面)。

4种常用的HTTP请求方法:

  • POST /uri 创建
  • DELETE /uri/xxx 删除
  • PUT /uri/xxx 更新或创建
  • GET /uri/xxx 查看

CRUD操作示例:

	PUT test
	{
	  "settings": {
	    "index":{
	      "number_of_shards":5,
	      "number_of_replicas":1
	    }
	  }
	}

	GET test/_settings
	GET _all/_settings
	GET .kibana,test/_settings

	#修改setting
	PUT test/_settings
	{
	  "number_of_replicas": 1
	}
	
	#shards必须一开始设置好,后期不能改 
	PUT test/_settings
	{
	 "number_of_shards":6
	}

	GET _all
	GET test
	
	#保存文档
	PUT test/job/1
	{
		"title":"python分布式爬虫开发",
		"salary_min":15000,
		"city":"北京",
		"company":
			{
			"name":"BaiDu",
			"company_addr":"BeiJing"
			},
		"publish_date":"2017-4-16",
		"comments":15
		}
	
	
	
	POST test/job/
	{
		"title":"elasticsearch",
		"salary_min":15000,
		"city":"HangZhou",
		"company":
			{
			"name":"AliBaBa",
			"company_addr":"HangZhou"
			},
		"publish_date":"2017-4-16",
		"comments":15
		}
	
	GET test/job/1
	
	GET test/job/1?_source=title,city
	GET test/job/1?_source
	
	
	#修改文章
	PUT test/job/1
	{
		"title":"python分布式爬虫开发",
		"salary_min":15000,
		"company":
			{
			"name":"BaiDu",
			"company_addr":"BeiJing"
			},
		"publish_date":"2017-4-16",
		"comments":20
		}
		
	POS test/job/1/_update
	{
	  "doc":{
	    "comments":30
	  }
	  
	}
	
	#删除
	DELETE  test/job/1
	DELETE test/job
	DELETE test

bulk批量操作

批量导入可以合并多个操作,比如index,delete,update,create等等。也可以帮助从一个索引导入到另一个索引。

bulk批量添加索引 示例:

POST _bulk
		{"index":{"_index":"test2","_type":"job2","_id":"2"}}
		{"tittle":"python分布式爬虫开发","publish_date":"2017-4-16","comments":15}
		{"index":{"_index":"test2","_type":"job3","_id":"3"}}
		{"tittle":"python django开发","publish_date":"2017-4-18","comments":50}

两行构成一个数据,不可再多添加换行符,否则出错;
delete行为只有一行。

本文地址:https://blog.csdn.net/weixin_43933037/article/details/85964314

相关标签: elasticsearch