如何使用Elasticsearch操作数据库呢?

使用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-优快云博客icon-default.png?t=O83Ahttps://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

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小星袁

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值