日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

elasticsearch 第四篇(API约定)

發布時間:2025/3/21 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 elasticsearch 第四篇(API约定) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

對多個indices進行操作

es中大多resetapi支持請求多個index, 例如”test1,test2,test3”,index也可以使用通配符, 例如”test*“, 還可以使用+,-來包含或移除某個或某類index, 例如”test*,-test1”
支持設置多個的api的請求字符串可設置以下參數:

  • ignore_unavailable: 是否忽略單個index是否可用(不存在或關閉), true表示忽略, false表示不忽略, 默認為false, 例如查詢已經關閉的index:

輸入:?GET /test1/user,account/_search?ignore_unavailable=false
輸出:

1 2 3 4 { "error": "IndexClosedException[[test1] closed]", "status": 403 }

輸入:?GET /test1/user,account/_search?ignore_unavailable=false
輸出:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 { "took": 1, "timed_out": false, "_shards": { "total": 0, "successful": 0, "failed": 0 }, "hits": { "total": 0, "max_score": 0, "hits": [] } }

  • allow_no_indices: 是否忽略通配符匹配不到index(不存在或關閉)的情況, true表示允許, false表示不允許,默認為true, 例如查詢已經關閉的index:

輸入:?GET /test*/_search?allow_no_indices=false
輸出:

1 2 3 4 { "error": "IndexMissingException[[test*] missing]", "status": 404 }

輸入:?GET /test*/_search?allow_no_indices=true

1 2 3 4 5 6 7 8 9 10 11 12 13 14 { "took": 1, "timed_out": false, "_shards": { "total": 0, "successful": 0, "failed": 0 }, "hits": { "total": 0, "max_score": 0, "hits": [] } }
  • expand_wildcards: 設置是否擴展通配符到closed的index中,open表示只在匹配并為open的index中查詢,closed表示在匹配的所有的index中查詢, 默認為closed, 例如查詢已經關閉的index
    輸入:?GEt /test*/_search?expand_wildcards=closed
    輸出:
    1 2 3 4 { "error": "IndexClosedException[[test1] closed]", "status": 403 }

公共參數

  • format: 表示返回數據的格式, 可選值為yaml和json兩種, 例如:
    輸入:?GET /test1/user/_search?format=yaml
    輸出:

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 --- took: 23 timed_out: false _shards: total: 5 successful: 5 failed: 0 hits: total: 1 max_score: 1.0 hits: - _index: "test1" _type: "user" _id: "1" _score: 1.0 _source: name: "silence"
  • pretty: 表示在已json格式返回數據時是否以可視化的格式返回, false或未在設置表示不格式化, 否則格式化

  • human: 表示是否對返回結果進行格式化處理,比如3600(s)顯示1h

  • 查詢結果過濾
    主要使用filter_path參數進行設置

1.在返回結果中我們只關注took, hits.total, hits.hits._id, hits._source, 則我們可以發起如此請求:
輸入:GET /test1/user/_search?filter_path=took,hits.total,hits.hits._id,hits.hits._source
輸出:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 { "took": 1, "hits": { "total": 1, "hits": [ { "_id": "1", "_source": { "name": "silence" } } ] } }

2.也可以使用統配符進行設置
輸入:?GET /_nodes/stats?filter_path=nodes.*.*ost*,nodes.*.os.*u
輸出:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 { "nodes": { "9jfW4VeWRta-Uq7Cq7bK34": { "host": "silence", "os": { "cpu": { "sys": 1, "user": 1, "idle": 96, "usage": 2, "stolen": 0 } } } } }

3.若層級較多時可使用**進行簡化
輸入:?GET /_nodes/stats?filter_path=nodes.**.*sys*
輸出:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 { "nodes": { "9jfW4VeWRta-Uq7Cq7bK34": { "os": { "cpu": { "sys": 2 } }, "process": { "cpu": { "sys_in_millis": 139106 } } } } }

4.若只需要_source中的某些值,則可以將filter_path和_source參數共同使用
輸入:?GET /test1/account/_search?filter_path=hits.hits._source&_source=firstname,lastname,gender&size=2
輸出:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 { "hits": { "hits": [ { "_source": { "firstname": "Rodriquez", "gender": "F", "lastname": "Flores" } }, { "_source": { "firstname": "Opal", "gender": "M", "lastname": "Meadows" } } ] } }

5.flat_settings用于設置在查詢setting時,setting中的key格式, 默認為false:
輸入:?GET /test1/_settings?flat_settings=true
輸出:

1 2 3 4 5 6 7 8 9 10 11 { "test1": { "settings": { "index.creation_date": "1442230557598", "index.uuid": "70bg061IRdKUdDNvgkUBoQ", "index.version.created": "1060099", "index.number_of_replicas": "1", "index.number_of_shards": "5" } } }

輸入:?GET /test1/_settings?flat_settings=false
輸出:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 { "test1": { "settings": { "index": { "creation_date": "1442230557598", "number_of_shards": "5", "uuid": "70bg061IRdKUdDNvgkUBoQ", "version": { "created": "1060099" }, "number_of_replicas": "1" } } } }

  • 請求參數格式
    1.boolean: 在es中將”0”, 0, false, “false”, “off”識別為false,其他均按ture處理
    2.number
    3.time: 可以提交一個以毫秒時間的整數或者以日期標識結尾的字符串,例如”2d”表示2天,支持的格式有: y(year),M(month),w(week),d(day),h(hour),m(minute),s(second)
    4.距離: 可以提交一個以米為單位的證書或者以距離表示結尾的字符串,例如”2km”表示2千米,支持的格式有: mi/miles(mile英里), yd/yards(yard碼), ft/feet(feet尺), in/inch(inch英寸), km/kilometers(kilometer千米), m/meters(meter米), cm/centimeters(centimeter厘米), mm/millimeters(millimeter毫米), NM/nmi/nauticalmiles(Nautical mile納米)
    5.模糊類型:
    a.數字,時間, IP:類似于range -fuzzines<=value<=+fuzzines
    b.字符串: 計算編輯距離

  • 返回結果中key的格式為駝峰還是下劃線分割, 通過case設置為camelCase則返回駝峰格式,否則為下劃線分割形式

  • jsonp: 可以用jsonp回調的方式調用es api, 需要通過callback設置回調函數名稱,并且需要在elasticsearch.yml中配置http.jsonp.enable: true來啟用jsonp格式

url訪問控制

可以通過代理方式進行es的url訪問控制,但是對于multi-search,multi-get和bulk等在請求參數中設置不同的index的情況很難解決.
為防止通過請求體設置index的情況,需要在elasticsearch.yml中設置rest.action.multi.allow_explicit_index:false, 此時es不允許在request body中設置index

如在修改前:
輸入:

1 2 3 4 5 POST /test1/user3/_bulk?pretty {"index" : {"_index" : "test2", "_type" : "user1", "_id" : 1}} {"name" : "silence1"} {"index" : {"_index" : "test2", "_type" : "user1", "_id" : 2}} {"name" : "silence2"}

輸出:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 { "took": 225, "errors": false, "items": [ { "index": { "_index": "test2", "_type": "user1", "_id": "1", "_version": 1, "status": 201 } }, { "index": { "_index": "test2", "_type": "user1", "_id": "2", "_version": 1, "status": 201 } } ] }

如在修改后(已重啟):
輸出:

1 2 3 4 { "error": "IllegalArgumentException[explicit index in bulk is not allowed]", "status": 500 }

輸入:

1 2 3 4 5 POST /test1/user3/_bulk?pretty {"index" : {"_id" : 1}} {"name" : "silence1"} {"index" : {"_id" : 2}} {"name" : "silence2"}

輸出:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 { "took": 8, "errors": false, "items": [ { "index": { "_index": "test1", "_type": "user3", "_id": "1", "_version": 1, "status": 201 } }, { "index": { "_index": "test1", "_type": "user3", "_id": "2", "_version": 1, "status": 201 } } ] }
from: http://imsilence.github.io/2015/09/16/elasticsearch/elasticsearch_04/


總結

以上是生活随笔為你收集整理的elasticsearch 第四篇(API约定)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 寡妇激情做爰呻吟 | 欧美色v| 蜜臀av免费一区二区三区水牛 | 美女黄视频大全 | 国产精品免费久久久久 | 欧美国产日本 | 米奇影视第四色 | 日韩精品一区二区电影 | 国产精品无码内射 | 伊人影视网 | 国产探花在线观看 | 手机在线中文字幕 | 中文字幕久久av | 亚洲av人无码激艳猛片服务器 | jzjzjzjzj亚洲成熟少妇 | 艳妇乳肉豪妇荡乳av | 亚洲色图清纯唯美 | 日韩中文字幕精品视频 | 精品久久久无码中文字幕边打电话 | 欧美r级在线观看 | 欧美国产精品一二三 | 国内精品人妻无码久久久影院蜜桃 | 国产精品mv | 俺啪也 | 久久久高清 | 日本黄色性视频 | fc2成人免费视频 | 一级做a爱片久久 | 欧美一级特黄aaaaaa大片在线观看 | 国产成人精品视频ⅴa片软件竹菊 | 久久久久久久国产精品视频 | 深夜成人福利视频 | 日本一级大片 | 久一视频在线 | 日韩www在线观看 | 一区二区传媒有限公司 | 99re在线视频精品 | 国产77777| 日韩操比 | 麻豆系列 | 亚洲成人av中文字幕 | www.youjizz.com日本 | 国产 xxxx| 一级黄色电影片 | 伊人网站在线观看 | 亚洲产国偷v产偷v自拍涩爱 | 久久中文av| 最新中文字幕免费 | 国产精品资源在线观看 | 乱淫av| 欧美亚洲伦理 | 中国黄色a级 | 久久国产精品无码一级毛片 | 久久精品网址 | 午夜影院试看 | 四川少妇xxx奶大xxx | 榴莲视频黄色 | 国产精品麻豆一区二区三区 | 日本不卡专区 | 伊人青青久 | 国产一区二区精品在线 | 日韩免费一二三区 | 国产亚洲欧美在线视频 | 色婷婷久久 | 男生把女生困困的视频 | 亚洲第二色 | 国产成人三级在线观看视频 | 91精品国产欧美一区二区成人 | 国产成人精品视频在线 | 色多多污| 欧美黄色xxx | 欧美丰满美乳xxx高潮www | 777四色 | 美女扒开腿让男生捅 | 黄色片网站在线免费观看 | 俺去日| 脱裤吧导航 | 国内激情自拍 | 激情五月综合网 | 国产99色 | 成人免费在线网站 | 一级生活毛片 | 久久久无码18禁高潮喷水 | 日日夜夜免费视频 | 久热草| 国产伦一区二区 | 国产成人在线影院 | 欧美资源在线 | 黄色视屏在线免费观看 | 一本一道久久a久久综合蜜桃 | 免费一级黄色 | 青青青视频免费观看 | 欧美一级免费黄色片 | 欧美激情视频一区二区三区 | av免费久久| 妺妺窝人体色www聚色窝仙踪 | 大香蕉精品一区 | 久久福利小视频 | 中文字幕第11页 |