废话不多说,直接上源码:这些数据格式,是在kibana格式化并且执行通过的。
1、创建表(索引)
请求:
PUT /user_search2
{
"mappings": {
"user_search_keyword2": {
"properties": {
"id": {
"type": "long"
},
"keyword_": {
"type": "text"
},
"type_": {
"type": "text"
},
"user_id": {
"type": "long"
},
"create_time": {
"type": "date"
}
}
}
}
}
返回结果:
#! Deprecation: the default number of shards will change from [5] to [1] in 7.0.0; if you wish to continue using the default of [5] shards, you must manage this on the create index request or with an index template
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "user_search2"
}
2、查询结构:
请求:
GET /user_search2/user_search_keyword2/_mapping
返回结果:
{
"user_search2" : {
"mappings" : {
"user_search_keyword2" : {
"properties" : {
"create_time" : {
"type" : "date"
},
"id" : {
"type" : "long"
},
"keyword_" : {
"type" : "text"
},
"type_" : {
"type" : "text"
},
"user_id" : {
"type" : "long"
}
}
}
}
}
}
3、添加测试数据
请求:
POST /user_search2/user_search_keyword2
{
"keyword_":"我来测试下",
"type_":"article",
"user_id":"711260",
"create_time":"2018-12-18"
}
返回结果:
{
"_index" : "user_search2",
"_type" : "user_search_keyword2",
"_id" : "Vpp1v2cBc3Sembhf9MFq",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}
4、查看数据
请求:
GET /user_search2/user_search_keyword2/_search
返回结果:
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [
{
"_index" : "user_search2",
"_type" : "user_search_keyword2",
"_id" : "Vpp1v2cBc3Sembhf9MFq",
"_score" : 1.0,
"_source" : {
"keyword_" : "我来测试下",
"type_" : "article",
"user_id" : "711260",
"create_time" : "2018-12-18"
}
}
]
}
}
5、删除
请求:
DELETE /user_search2
返回结果:
{
"acknowledged" : true
}
|