ES文档

1.创建 index

### 创建 index
PUT http://localhost:9200/questions

2.删除一个Index

### 删除一个Index
DELETE http://localhost:9200/questions

3.设置index中的文档属性采用ik分词

### 设置index中的文档属性采用ik分词
POST http://localhost: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"
    }
  }
}

4.questions 中添加文档

### questions 中添加文档
POST http://localhost:9200/questions/_create/1
Content-Type: application/json

{
  "id":1,
  "title":"Java基本数据类型有哪些",
  "content":"面时候为啥要问基本类型这么简单问题呀,我们要如何回答呢?"
}
### questions 中添加文档
POST http://localhost:9200/questions/_create/2
Content-Type: application/json

{
  "id":2,
  "title":"int类型的范围",
  "content":"为啥要了解int类型的范围呢?"
}

### questions 中添加文档
POST http://localhost:9200/questions/_create/3
Content-Type: application/json

{
  "id":3,
  "title":"常用集合类有哪些",
  "content":"为啥企业经常问集合呀?该如何回复呢"
}

### questions 中添加文档
POST http://localhost:9200/questions/_create/4
Content-Type: application/json

{
  "id":4,
  "title":"线程的run方法和start方法有啥区别",
  "content":"run方法可以执行线程的计算过程, start也可以执行线程的计算过程,用途一样么?"
}

5.更新questions索引中的文档

### 更新questions索引中的文档
POST http://localhost:9200/questions/_doc/4/_update
Content-Type: application/json

{
  "doc": {
    "title": "Java线程的run方法和start方法有啥区别"
  }
}

6.删除questions中的一个文档

### 删除questions中的一个文档
DELETE http://localhost:9200/questions/_doc/2

7.查询数据

### 查询数据
GET http://localhost:9200/questions/_doc/4

8.搜索 ES

### 搜索 ES
POST http://localhost:9200/questions/_search
Content-Type: application/json

{
  "query": { "match": {"title": "类型" } }
}

9.多字段搜索

### 多字段搜索
POST http://localhost:9200/questions/_search
Content-Type: application/json

{
  "query": {
    "bool": {
      "should": [
        { "match": { "title":  "java类型" }},
        { "match": { "content": "java类型"}}
      ]
    }
  }
}
posted @ 2022-06-27 18:02  约拿小叶  阅读(55)  评论(0编辑  收藏  举报