es数据插入和查询

1、es数据插入

es入库字段不可超过1000个字段,超过后无法存入es。建议不超过20个字段

1)批量插入

请求路径 IP:端口/_bulk,每条数据前加具体索引信息

{"index":{"_index": "jzms_monitor_info_1","_type": "_doc"}}
说明:jzms_monitor_info_1是索引名
以下是发送2条请求报文:
{"index":{"_index": "jzms_monitor_info_1","_type": "_doc"}}
{"appName" : "应用11","appId" : "1111","requestAppID" : "222","startTime" : "20210901101010","requestAppName" : "应用2","id" : "21c02e722fdb4141bdc365d01b45262c","serviceID" : "440000-zfba-xsajbl-la","requestData" : {"ajbh" : "123456","acbrsfzh1" : "44"},"apiID" : "/api/v1/zfba-xsajbl-la/lahgxjcUsingPOST","reportTime":"20211201101010"}
{"index":{"_index": "jzms_monitor_info_1","_type": "_doc"}}
{"appName" : "应用12","appId" : "1111","requestAppID" : "222","startTime" : "20210901101010","requestAppName" : "应用2","id" : "21c02e722fdb4141bdc365d01b45262c","serviceID" : "440000-zfba-xsajbl-la","requestData" : {"ajbh" : "123456","acbrsfzh1" : "22"},"apiID" : "/api/v1/zfba-xsajbl-la/lahgxjcUsingPOST","reportTime":"20211201101010"}

执行成功的返回

2)单条插入

请求路径:IP:端口/索引名/_doc
请求报文放入请求数据即可。

2、es数据查询

1)查询索引全部数据

GET /jzms_monitor_info/_search
{
"query": {
"match_all": {}
}
}

2)删除索引全部数据

这种方法删除速度比较慢
POST /jzms_monitor_info/_delete_by_query?pretty
{
"query": {
"match_all": {}
}
}
kibana平台上直接删除索引再重建索引较快,如下所示:

3)索引创建

PUT /jzms_monitor_info

{
"settings": {
"number_of_shards": 1
},
"mappings": {
"_doc": {
"properties": {
"appId": { "type": "keyword" },
"appName": { "type": "text" },
"reportTime": { "type": "keyword" },
"serviceID": { "type": "keyword" },
"serviceType": { "type": "keyword" },
"apiID": { "type": "keyword" },
"startTime": { "type": "keyword" },
"requestAppId": { "type": "keyword" },
"requestAppName": { "type": "text" },
"requestData": {
"type": "object",
"dynamic": true
}
}
}
}
}

4)带条件的查询

3、es启动命令

service elasticsearch start

posted on 2021-12-15 10:21  seamy  阅读(5814)  评论(0编辑  收藏  举报