elasticsearch中經常使用的API

 elasticsearch中經常使用的API分類以下:html

  • 文檔API: 提供對文檔的增刪改查操做node

  • 搜索API: 提供對文檔進行某個字段的查詢緩存

  • 索引API: 提供對索引進行操做,查看索引信息等app

  • 查看API: 按照更直觀的形式返回數據,更適用於控制檯請求展現curl

  • 集羣API: 對集羣進行查看和操做的APIelasticsearch

  下面簡單的一一介紹記錄一下。ide

  文檔類APIpost

  Index API: 建立並創建索引優化

  PUT twitter/tweet/1{ "user" : "kimchy", "post_date" : "2009-11-15T14:12:12", "message" : "trying out Elasticsearch"}ui

  官方文檔參考:Index API

  Get API: 獲取文檔

  curl -XGET 'http://localhost:9200/twitter/tweet/1'

  官方文檔參考:Get API

  DELETE API: 刪除文檔

  $ curl -XDELETE 'http://localhost:9200/twitter/tweet/1'

  官方文檔參考:Delete API

  UPDATE API: 更新文檔

  PUT test/type1/1{ "counter" : 1, "tags" : ["red"]}

  官方文檔參考:Update API

  Multi Get API: 一次批量獲取文檔

  curl 'localhost:9200/_mget' -d '{ "docs" : [{ "_index" : "test", "_type" : "type", "_id" : "1" }, { "_index" : "test", "_type" : "type", "_id" : "2" } ]}'

  官方文檔參考:Multi Get API

  Bulk API: 批量操做,批量操做中能夠執行增刪改查

  $ curl -s -XPOST localhost:9200/_bulk --data-binary "@requests"; echo{"took":7, "errors": false, "items": [{"index":{"_index":"test","_type":"type1","_id":"1","_version":1,"result":"created","forced_refresh":false}}]}

  官方文檔參考:Bulk API

  DELETE By Query API: 根據查詢刪除

  POST twitter/_delete_by_query{ "query": { "match": { "message": "some message" } }}

  官方文檔參考:Delete By Query API

  Update By Query API: 根據查詢更新

  POST twitter/_update_by_query?conflicts=proceed

  官方文檔參考:Update By Query API

  Reindex API:重建索引

  POST _reindex{ "source": { "index": "twitter" }, "dest": { "index": "new_twitter" }}

  官方文檔參考:Reindex API

  Term Vectors: 詞組分析,只能針對一個文檔

  curl -XGET 'http://localhost:9200/twitter/tweet/1/_termvectors?pretty=true'

  官方文檔參考:Term Vectors

  Multi termvectors API: 多個文檔的詞組分析

  curl 'localhost:9200/_mtermvectors' -d '{ "docs": [{ "_index": "testidx", "_type": "test", "_id": "2", "term_statistics": true }, { "_index": "testidx", "_type": "test", "_id": "1", "fields": ["text" ] } ]}'

  官方文檔參考:Multi termvectors API。 更多關於文檔類API請參考:Document APIs

  搜索類API

  URI Search:url中傳參

  GET twitter/tweet/_search?q=user:kimchy

  官方文檔參考:URI Search

  Request Body搜索接口: 搜索的條件在請求的body中

  GET /twitter/tweet/_search{ "query" : { "term" : { "user" : "kimchy" } }}

  官方文檔參考:Request Body Search

  • 搜索模版設置接口: 能夠設置搜索的模版,模版的功能是能夠根據不一樣的傳入參數,進行不一樣的實際搜索

  • 搜索分片查詢接口: 查詢這個搜索會使用到哪一個索引和分片

  • Suggest接口: 搜索建議接口,輸入一個詞,根據某個字段,返回搜索建議。

  • 批量搜索接口: 把批量請求放在一個文件中,批量搜索接口讀取這個文件,進行搜索查詢

  • Count接口: 只返回符合搜索的文檔個數

  • 文檔存在接口: 判斷是否有符合搜索的文檔存在

  • 驗證接口: 判斷某個搜索請求是否合法,不合法返回錯誤信息

  • 解釋接口: 使用這個接口能返回某個文檔是否符合某個查詢,爲何符合等信息

  • 抽出器接口: 簡單來講,能夠用這個接口指定某個文檔符合某個搜索,事先未文檔創建對應搜索

  官方文檔參考:Search APIS

  索引類API

  • 建立索引接口(POST my_index)

  • 刪除索引接口(DELETE my_index)

  • 獲取索引信息接口(GET my_index)

  • 索引是否存在接口(HEAD my_index)

  • 打開/關閉索引接口(my_index/_close, my_index/_open)

  • 設置索引映射接口(PUT my_index/_mapping)

  • 獲取索引映射接口(GET my_index/_mapping)

  • 獲取字段映射接口(GET my_index/_mapping/field/my_field)

  • 類型是否存在接口(HEAD my_index/my_type)

  • 刪除映射接口(DELTE my_index/_mapping/my_type)

  • 索引別名接口(_aliases)

  • 更新索引設置接口(PUT my_index/_settings)

  • 獲取索引設置接口(GET my_index/_settings)

  • 分析接口(_analyze): 分析某個字段是如何創建索引的

  • 創建索引模版接口(_template): 爲索引創建模版,之後新建立的索引均可以按照這個模版進行初始化

  • 預熱接口(_warmer): 某些查詢能夠事先預熱,這樣預熱後的數據存放在內存中,增長後續查詢效率

  • 狀態接口(_status): 索引狀態

  • 批量索引狀態接口(_stats): 批量查詢索引狀態

  • 分片信息接口(_segments): 提供分片信息級別的信息

  • 索引恢復接口(_recovery): 進行索引恢復操做

  • 清除緩存接口(_cache/clear): 清除全部的緩存

  • 輸出接口(_flush)

  • 刷新接口(_refresh)

  • 優化接口(_optimize): 對索引進行優化

  • 升級接口(_upgrade): 這裏的升級指的是把索引升級到lucence的最新格式

  官方文檔參考:Indices APIS

  查看類API

  • 查看別名接口(_cat/aliases): 查看索引別名

  • 查看分配資源接口(_cat/allocation)

  • 查看文檔個數接口(_cat/count)

  • 查看字段分配狀況接口(_cat/fielddata)

  • 查看健康狀態接口(_cat/health)

  • 查看索引信息接口(_cat/indices)

  • 查看master信息接口(_cat/master)

  • 查看nodes信息接口(_cat/nodes)

  • 查看正在掛起的任務接口(_cat/pending_tasks)

  • 查看插件接口(_cat/plugins)

  • 查看修復狀態接口(_cat/recovery)

  • 查看線城池接口(_cat/thread_pool)

  • 查看分片信息接口(_cat/shards)

  • 查看lucence的段信息接口(_cat/segments)

  官方文檔參考:Cat APIS

  集羣類API

  • 查看集羣健康狀態接口(_cluster/health)

  • 查看集羣情況接口(_cluster/state)

  • 查看集羣統計信息接口(_cluster/stats)

  • 查看集羣掛起的任務接口(_cluster/pending_tasks)

  • 集羣從新路由操做(_cluster/reroute)

  • 更新集羣設置(_cluster/settings)

  • 節點狀態(_nodes/stats)

  • 節點信息(_nodes)

  • 節點的熱線程(_nodes/hot_threads)

  • 關閉節點(/nodes/_master/_shutdown)

  官方文檔參考:Cluster APIS。 盡在:https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html

相關文章
相關標籤/搜索