第十九节 通过PostMan操作ElasticSearch实现增删改查

亮子 2023-09-02 12:47:23 19875 0 0 0

1、查看安装了哪些插件

GET http://192.168.80.131:9200/_cat/plugins

图片alt

2、查询有哪些索引

GET http://192.168.80.131:9200/_cat/indices

图片alt

3、创建索引

  • 不带映射创建索引
PUT http://192.168.80.131:9200/tb_hero

图片alt

  • 带映射创建索引
PUT http://192.168.80.131:9200/tb_hero
{
  "mappings": {
    "properties":{
	  "id":{
			"type":"long"
		},
        "name":{
			"type":"keyword"
		},
        "tech":{
			"type":"text",
			"analyzer":"ik_max_word",
			"search_analyzer":"ik_smart"
		},
		"age":{
			"type":"integer"
		},
        "update_time":{
			"type":"date"
		}
	}
  }
	
}

图片alt

4、创建映射

PUT http://192.168.80.131:9200/tb_hero/_mapping
{
    "properties":{
	  "id":{
			"type":"long"
		},
        "name":{
			"type":"keyword"
		},
        "tech":{
			"type":"text",
			"analyzer":"ik_max_word",
			"search_analyzer":"ik_smart"
		},
		"age":{
			"type":"integer"
		},
        "update_time":{
			"type":"date"
		}
	}
}

图片alt

5、查看索引

GET http://192.168.80.131:9200/tb_hero

图片alt

6、删除索引

DELETE http://192.168.80.131:9200/tb_hero

图片alt

7、测试分词

  • 所有语言的默认使用的就是这个标准分词器
# 方法1:
GET http://192.168.80.131:9200/_analyze
# 方法2:
POST http://192.168.80.131:9200/_analyze
{
  "analyzer":"standard",
  "text":"武松打虎"
}

图片alt

  • IK分词器

1)、ik_smart

http://192.168.80.131:9200/_analyze?pretty=true
{
  "analyzer":"ik_smart",
  "text":"武松打虎"
}

图片alt

2)、ik_max_word

GET http://192.168.80.131:9200/_analyze?pretty=true
{
  "analyzer":"ik_max_word",
  "text":"武松打虎"
}

图片alt

8、添加文档

POST http://192.168.80.131:9200/tb_hero/_doc/1
{
	"id": 1,
	"name": "武松",
	"tech": "景阳冈打虎",
    "age": 66,
	"update_time": "2020-12-11"
}

图片alt

9、根据ID查询文档

GET http://192.168.80.131:9200/tb_hero/_doc/1

图片alt

10、全匹配查询

GET http://192.168.80.131:9200/tb_hero/_search

图片alt

11、单文档全量修改

PUT http://192.168.80.131:9200/tb_hero/_doc/1
{
	"id": 1,
	"name": "武松",
	"tech": "景阳冈打虎,醉打蒋门神",
    "age": 38,
	"update_time": "2023-09-03"
}

图片alt

11、单文档局部修改

POST http://192.168.80.131:9200/tb_hero/_update/1
{
    "doc": {
        "age": 33
    }
}

图片alt

12、根据ID删除文档

DELETE http://192.168.80.131:9200/tb_hero/_doc/1

图片alt

13、条件查询

根据英雄的技能查询

GET http://192.168.80.131:9200/tb_hero/_search
{
    "query":{
        "match":{
            "tech": "草料"
        }
    }
}

图片alt

参考文档