使用Elasticsearch操作数据
### 创建一个index(questions)
PUT http://172.26.6.53:9200/questions
### 删除一个指定的index
DELETE http://172.26.6.53:9200/questions
### 设置index中的文档属性,采用ik_max_word
POST http://172.26.6.53:9200/questions/_mapping
Content-Type: application/json
{
"properties":{
"title": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
},
"content": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}
}
### questions中添加文档
POST http://172.26.6.53:9200/questions/_create/1
Content-Type: application/json
{
"id": 1,
"title": "Java基本数据类型都有哪些?",
"content": "这么简单的问题,不想回答"
}
### questions中添加文档
POST http://172.26.6.53:9200/questions/_create/2
Content-Type: application/json
{
"id": 2,
"title": "你会微服务吗?都使用过哪些组件",
"content": "这个问题也太简单了,微服务组件有Nacos、Seata等等"
}
### questions中添加文档
POST http://172.26.6.53:9200/questions/_create/3
Content-Type: application/json
{
"id": 3,
"title": "Nacos的作用是哪些?",
"content": "注册中心、配置中心等等"
}
### questions中添加文档
POST http://172.26.6.53:9200/questions/_create/4
Content-Type: application/json
{
"id": 4,
"title": "String类型是基本类型吗?",
"content": "String类型不是基本类型,是引用类型"
}
### 指定文档编号去查询(比如查询4)
GET http://172.26.6.53:9200/questions/_doc/4
### 指定文档,更新内容(比如:4)
POST http://172.26.6.53:9200/questions/_doc/4/_update
Content-Type: application/json
{
"doc": {
"content": "String是引用类型"
}
}
### 删除指定文档
DELETE http://192.168.144.160:9200/questions/_doc/4
### 指定title列进行模糊查询,查询条件(比如查询"微服务")
POST http://192.168.144.160:9200/questions/_search
Content-Type: application/json
{
"query": {
"match": {
"title": "微服务"
}
}
}
### 多字段查询(must--and)
POST http://192.168.144.160:9200/questions/_search
Content-Type: application/json
{
"query": {
"bool": {
"must": [
{"match": {"title": "微服务"}},
{"match": {"content": "类型"}}
]
}
}
}
### 多字段查询(should--or)
POST http://192.168.144.160:9200/questions/_search
Content-Type: application/json
{
"query": {
"bool": {
"should": [
{"match": {"title": "微服务"}},
{"match": {"content": "类型"}}
]
}
}
}
上一篇文章:安装和启动ElasticSearch-优快云博客https://blog.youkuaiyun.com/Z0412_J0103/article/details/143566202下一篇文章: SpringBoot操作Elasticsearch文章浏览阅读453次,点赞14次,收藏4次。Elasticsearch可以非常方便地进行数据的多维分析,所以大数据分析领域也经常会见到它的身影,生产环境中绝大部分新产生的数据可以通过应用直接导入,但是历史或初始数据可能会需要单独处理,这种情况下可能遇到需要导入大量数据的情况 这里简单分享一下批量导入数据的操作方法与相关基础,还有可能会碰到的问_springboot3支持elasticsearch7版本
https://blog.youkuaiyun.com/Z0412_J0103/article/details/143570062