elasticsearch的综合测试案例
–查看指定数据库testindex中所有type的结构
GET /testindex/_mapping
GET /testindex/_settings,_mappings
–删除索引
DELETE /testindex
–添加索引
PUT /testindex
{
"settings": {
"number_of_shards" : 3,
"number_of_replicas" : 0
}
}
–添加type
PUT /testindex/user/_mapping
{
"user": {
"properties": {
"name": {
"type": "text",
"analyzer": "standard",
"search_analyzer": "standard"
},
"sex": {
"type": "short"
},
"birthday": {
"type": "date",
"include_in_all": "false"
},
"webclass": {
"type": "keyword"
},
"eduname": {
"type": "keyword",
"index": "not_analyzed"
},
"selfment": {
"type": "text"
},
"refreshtime": {
"type": "date",
"format" : "date_optional_time"
}
}
}
}
–添加type
PUT /testindex/user/_mapping
{
"user": {
"_all": {
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart"
},
"properties": {
"name": {
"type": "text",
"analyzer": "standard",
"search_analyzer": "standard"
},
"sex": {
"type": "short"
},
"birthday": {
"type": "date",
"include_in_all": "false"
},
"webclass": {
"type": "keyword"
},
"eduname": {
"type": "keyword",
"index": "not_analyzed"
},
"selfment": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_smart",
"include_in_all": "true"
},
"refreshtime": {
"type": "date",
"format" : "date_optional_time"
}
}
}
}
–插入数据
PUT testindex/user/1
{
"name" : "kimchy",
"sex" : 1,
"birthday" : "1998-10-02",
"webclass" : "www.a.com",
"eduname" : "大专",
"selfment" : "我是中国人,我爱中国,中华人民共和国国歌",
"refreshtime" : "2017-02-20T12:20:23.000"
}
–批量插入数据:
POST /testindex/user/_bulk
{ "create": { "_id": "1" }}
{ "name": "张三","sex":1,"birthday": "1998-10-02","webclass" : "www.b.com","eduname" : "大专","selfment" : "我爱中国","refreshtime" : "2017-02-10T12:20:23.000" }
{ "create": { "_id": "2" }}
{ "name": "李四","sex":2,"birthday": "1988-10-02","webclass" : "www.a.com","eduname" : "本科","selfment" : "我是中国人,我也爱中国,还有中华人民共和国国歌","refreshtime" : "2017-02-20T12:20:23.020" }
{ "create": { "_id": "3" }}
{ "name": "王五","sex":1,"birthday": "1988-10-02","webclass" : "www.a.com","eduname" : "大专","selfment" : "我是中国人,我喜欢中华人民共和国国歌","refreshtime" : "2017-02-20T13:20:23.000" }
–批量删除数据
POST /testindex/user/_bulk
{ "delete": { "_id": "1" }}
{ "delete": { "_id": "2" }}
{ "delete": { "_id": "3" }}
–分词查询
GET /testindex/user/_search
{
"query" : {
"bool" : {
"must": { "match": { "_all": "中国人民共和国国歌" }},
"filter" : { "term" : { "webclass" : "www.a.com" }}
}
},
"sort": [
{ "refreshtime": { "order": "desc" }},
{ "_score": { "order": "desc" }}
]
}
–分页查询
GET /testindex/user/_search
{
"from": 2,
"size": 2
}
还没有评论,来说两句吧...