Elasticsearch-Head基本使用方法


一、創建索引index和mapping

可參考https://www.cnblogs.com/wenbronk/p/9395861.html

(1)

請求方式:PUT

路徑輸入框:索引名

內容輸入框:

{
  "mappings": {
    "_doc": {
      "properties": {
        "args": {
          "type": "text",
          "fields": {
            "keyword": {
              "ignore_above": 256,
              "type": "keyword"
            }
          }
        },
        "result": {
          "type": "text",
          "fields": {
            "keyword": {
              "ignore_above": 256,
              "type": "keyword"
            }
          }
        },
        "method": {
          "type": "text",
          "fields": {
            "keyword": {
              "ignore_above": 256,
              "type": "keyword"
            }
          }
        },
        "createTime": {
          "format": "yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis",
          "type": "date"
        },
        "takeTime": {
          "type": "long"
        },
        "appId": {
          "type": "text",
          "fields": {
            "keyword": {
              "ignore_above": 256,
              "type": "keyword"
            }
          }
        },
        "groupId": {
          "type": "long"
        },
        "resultSize": {
          "type": "long"
        },
        "id": {
          "type": "text",
          "fields": {
            "keyword": {
              "ignore_above": 256,
              "type": "keyword"
            }
          }
        },
        "interfaceName": {
          "type": "text",
          "fields": {
            "keyword": {
              "ignore_above": 256,
              "type": "keyword"
            }
          }
        },
        "interfaceCode": {
          "type": "text",
          "fields": {
            "keyword": {
              "ignore_above": 256,
              "type": "keyword"
            }
          }
        }
      }
    }
  }
}

 

二、刪除索引

(1)刪除單個索引

請求方式:DELETE

路徑輸入框:/索引名

內容輸入框默認

 

(2)刪除多個索引

請求方式:DELETE

路徑輸入框:/索引名1,索引名2

內容輸入框默認

 

(3)刪除以XX開頭的所有索引文件(刪除以testindex 開頭的所有索引文件,如配置文件禁止此方式后不能使用)

請求方式:DELETE

路徑輸入框:/testindex*

內容輸入框默認

 

(4)刪除全部索引(如配置文件禁止此方式后不能使用)

請求方式:DELETE

路徑輸入框: /_all

內容輸入框默認

 

三、插入數據

(1)查看表結構,概覽-索引信息,mappings下的第一個字段關鍵字,即是文檔名稱_doc

(2)復合查詢-查詢,插入數據

請求方式:POST

路徑輸入框:索引名稱/文檔名稱/主鍵編號,例:testindex/_doc/1200001

內容輸入框:填入

{
    "args":"xx",
    "result":"xx",
    "method":"xx",
    "createTime":"2019/05/08 16:26:49",
    "takeTime":"2019/05/08 16:26:49",
    "appId":"xxxxxx",
    "groupId":"1",
    "resultSize":"100",
    "id":"1",
    "interfaceName":"接口名稱",
    "interfaceCode":"abc"
}

 

四、刪除數據

(1)據主鍵刪除數據

請求方式:DELETE,路徑輸入框:/索引名稱/文檔名稱/主鍵編號,內容輸入框默認{"query":{"match_all":{}}}

 

(2)據匹配條件刪除數據(該過程沒有回滾,只有中斷)

請求方式:POST,路徑輸入框:索引名稱/文檔名稱/_delete_by_query,內容輸入框填搜索條件

例1:匹配具體用戶 例: { "query":{ "term":{ "_id":100000100 } } }

例2::不存在:包含兩種意思:1.這條數據根本就沒有這個字段,2.這條數據的字段的值為null

查詢檢查一下
test/user-feature/_search
{
     "query" :{
         "bool" :{
             "must_not" :{
                 "exists" :{
                     "field" : "phone_aes"
                 }
             }
         }
     }
}
  
刪除
test/user-feature/_delete_by_query
{
     "query" :{
         "bool" :{
             "must_not" :{
                 "exists" :{
                     "field" : "phone_aes"
                 }
             }
         }
     }
}
 
例3:存在
刪除
test/user-feature/_delete_by_query
{
     "query" :{
         "bool" :{
             "must" :{
                 "exists" :{
                     "field" : "phone_aes"
                 }
             }
         }
     }
}
 
例4:等於多少則刪除
test/_doc/_delete_by_query
{
     "query" :{
         "bool" :{
             "must" :{
                 "term" :{
                     "flowId" : 182
 
                 }
             }
         }
     }
}
 

(3)刪除所有數據(只刪數據,不刪表結構)

請求方式:POST,路徑填入框:/索引名稱/文檔名稱/_delete_by_query?pretty,內容輸入框默認{"query":{"match_all":{}}}

 

五、查詢

(1)組合查詢

test/_doc/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "flowId": 184
          }
        },
        {
          "match": {
            "requestJson": "15728898901"
          }
        }
      ]
    }
  }
}

 

(2)查詢某列最大最小值

test/_search
{
  "_source": [
    "importedTime"
  ],
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "flowId": 258
          }
        }
      ]
    }
  },
  "aggs": {
    "max_time": {
      "max": {
        "field": "importedTime"
      }
    },
    "min_time": {
      "min": {
        "field": "importedTime"
      }
    }
  }
}

 

六、調整索引所能讀取的最大數量

請求方式:PUT,路徑填入框:/索引名稱/_settings,內容輸入框默認{"index":{"max_result_window":1000000}}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM