首页 > 技术文章 > ElasticSearch通过Rest Http API完成基本操作

zplogo 2018-01-15 16:36 原文

新建一个包含文档类别及字段定义的culture索引,PUT http://127.0.0.1:9200/culture

 1 {
 2     "settings": {
 3         "index": {
 4             "number_of_shards": "2", 
 5             "number_of_replicas": "1"
 6         }
 7     }, 
 8     "mappings": {
 9         "book": {
10             "properties": {
11                 "ISBN": {
12                     "type": "keyword"
13                 }, 
14                 "author": {
15                     "type": "text"
16                 }, 
17                 "book_name": {
18                     "type": "text"
19                 }, 
20                 "book_words": {
21                     "type": "integer"
22                 }, 
23                 "classify": {
24                     "type": "text", 
25                     "fielddata": true
26                 }, 
27                 "public_time": {
28                     "type": "date", 
29                     "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
30                 }, 
31                 "publish_house": {
32                     "type": "text"
33                 }
34             }
35         }
36     }
37 }
View Code

 新增文档数据

PUT http://127.0.0.1:9200/culture/book/1

1 {
2     "book_name": "平凡的世界", 
3     "author": "路遥", 
4     "classify": "文学", 
5     "publish_house": "人民教育出版社", 
6     "public_time": "1970-10-15", 
7     "book_words": "35000", 
8     "ISBN": "855-555-5552-203-9655"
9 }
View Code

POST http://127.0.0.1:9200/culture/book/2

{
    "book_name": "白鹿原", 
    "author": "陈忠实", 
    "classify": "文学", 
    "publish_house": "人民教育出版社", 
    "public_time": "1980-10-15", 
    "book_words": "38000", 
    "ISBN": "6666-2"
}
View Code

POST http://127.0.0.1:9200/culture/book/3

1 {
2     "book_name": "野草集", 
3     "author": "龙应台", 
4     "classify": "文学", 
5     "publish_house": "台湾出版社", 
6     "public_time": "1990-10-15", 
7     "book_words": "18000", 
8     "ISBN": "6666-3"
9 }
View Code

POST http://127.0.0.1:9200/culture/book/4

 

1 {
2     "book_name": "康熙王朝", 
3     "author": "二月河", 
4     "classify": "历史", 
5     "publish_house": "河南出版社", 
6     "public_time": "2005-10-15", 
7     "book_words": "48000", 
8     "ISBN": "6666-4"
9 }
View Code

 

POST http://127.0.0.1:9200/culture/book/5

1 {
2     "book_name": "Java核心技术(第十一版)", 
3     "author": "Bluce Lee", 
4     "classify": "计算机", 
5     "publish_house": "图灵出版社", 
6     "public_time": "2017-11-15", 
7     "book_words": "15000", 
8     "ISBN": "6666-5"
9 }
View Code

 

POST http://127.0.0.1:9200/culture/book/6

1 {
2     "book_name":"蔬菜栽培",
3     "author":"张某某",
4     "classify":"其他",
5     "publish_house":"人民劳动出版社",
6     "public_time":"2016-11-15",
7     "book_words":"5000",
8     "ISBN":"6666-6"
9 }
View Code

 

POST http://127.0.0.1:9200/culture/book (自动生成id)

1 {
2     "book_name":"倚天独龙记",
3     "author":"金庸",
4     "classify":"武侠",
5     "publish_house":"人民劳动出版社",
6     "public_time":"2016-11-15",
7     "book_words":"5000",
8     "ISBN":"6666-7"
9 }
View Code

 

推荐阅读