美文网首页
elasticsearch json语句

elasticsearch json语句

作者: 五岁小孩 | 来源:发表于2021-04-23 12:21 被阅读0次

    elasticsearch json语句

    清空索引下的数据

    • 请求

      DELETE http://192.168.21.224:19200/iepms_device_data_2020/
      {
          "query": {
              "match_all": {
              }
          }
      }
      

    创建索引映射

    • 问题

      如下创建索引映射:
      
      若LinedId出现:
      
      "LineId": {
               "type": "text",
                   "fields": {
                       "keyword": {
                           "ignore_above": 256,
                           "type": "keyword"
                       }
                   }
           },
      
      则是由于LineId字段类型类型冲突导致(字段已存在时重建时出现)
      
      正常的字段类型:
      
      "LineId": {
               "type": "keyword"
           },
      
    • 解决

      Put http://192.168.21.224:19200/iepms_device_data_2020/_mapping/IepmsDeviceData/
      {
       "properties": {
           "AlarmReason": {
               "type": "keyword"
           },
              "LineId": {
               "type": "keyword"
           },
           "DataTime": {
               "type": "date"
           },
           "DataValue": {
               "type": "double"
           },
           
           "LineName": {
               "type": "keyword"
           },
           "Memo": {
               "type": "text"
           },
           "MemoUser": {
               "type": "text"
           },
           "ProcessId": {
               "type": "keyword"
           },
           "ProcessName": {
               "type": "keyword"
           },
           "Site": {
               "type": "integer"
           },
           "Status": {
               "type": "integer"
           },
           "StatusEnd": {
               "type": "date"
           },
           "TimeLength": {
               "type": "integer"
           },
           "ValueFrom": {
               "type": "double"
           },
           "ValueTo": {
               "type": "double"
           }
       }
      }
      

    时间聚合查询

    • 请求

      curl -H 'Content-type:application/json'  -XGET http://192.168.21.224:19200/nfdas_link_snmp_data_202004/_search?pretty -d '{ 
         "size" : 0,
         "aggs": {
            "sales": {
               "date_histogram": {
                  "field": "Time",
                  "interval": "1h", 
                   "time_zone":"+08:00",
                  "format": "yyyy-MM-dd HH"
               },
                 "aggregations": {
                     "Inbound_return" : {
                         "sum" : { 
                             "field" : "Inbound"
                         } 
                     },
                     "Outbound_return" : { 
                         "sum" : {
                             "field" : "Outbound" 
                         } 
                     }
                  }
            }
         }
      }'
      

    查询字段大于小于(Range)

    • 请求

      {
          "query":{
              "range":{
                  "inbound":{
                      "gte":0,
                       "lte":1
                  }
              }
          }
      }
      

    删除时间范围内数据

    • 请求

      POST http://192.168.21.224:19200/[索引名]iepms_device_data_2020/[索引类型/文档名]IepmsDeviceData/
           _delete_by_query
      {
        "query": {
          "range": {
             "DataTime": {
                            "from": "2020-05-15T05:00:00.000Z",
                            "to": "2020-05-16T05:30:00.000Z"
                          }
          }
        }
      }
      

    相关文章

      网友评论

          本文标题:elasticsearch json语句

          本文链接:https://www.haomeiwen.com/subject/fnihrktx.html