日韩性视频-久久久蜜桃-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约定)的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 精品国产乱码久久久久久免费 | 中文天堂在线播放 | 免费日韩在线视频 | 欧美精品大片 | 国产一级久久久久毛片精品 | 一区不卡av| 狠狠做深爱婷婷久久综合一区 | 伊人成人在线视频 | 激情亚洲网| 99热在线免费观看 | 欧美精品手机在线 | 好吊色一区二区三区 | av黄色网| 欧美精品一二三 | 成年人免费大片 | 天堂中文网在线 | 9i看片成人免费高清 | 99成人国产精品视频 | 一区精品在线观看 | 好逼天天操| 免费视频亚洲 | 一本大道久久a久久精二百 琪琪色在线视频 | 久久精品视频一区 | 国产精品久久久久久久久毛片 | 国产真人毛片 | 夫妻露脸自拍[30p] | 在线免费观看亚洲 | 91精品综合久久 | 成熟人妻av无码专区 | 快播在线视频 | 天天躁日日摸久久久精品 | 国产精品探花在线观看 | 精品不卡一区二区三区 | 国产成人免费av一区二区午夜 | 五月天视频网站 | 亚洲欧美激情在线 | 在线免费观看视频你懂的 | 国产美女三级无套内谢 | 香蕉成人在线视频 | 午夜激情免费 | 久久久一 | 久艹av| av观看国产 | 综合激情网站 | 尤物视频免费观看 | 国产精品s | 一级日韩毛片 | 91黄色小网站 | 福利在线网站 | 国产乡下妇女三片 | 奇米中文字幕 | 在线爱情大片免费观看大全 | 免费久久精品 | 韩国一区二区在线播放 | 日韩精品国产一区 | 日韩一卡二卡三卡四卡 | 成人导航网站 | 久久久无码精品亚洲无少妇 | 精品国偷自产国产一区 | 精品成人一区二区 | 亚洲精品乱码久久久久久不卡 | 一级做a爱视频 | 午夜免费福利影院 | 热热久| 最新中文字幕在线视频 | av小说天堂网| 欧美韩一区二区 | 国产全肉乱妇杂乱视频 | 2018狠狠干 | 一级免费视频 | 亚洲图片在线 | 懂色一区二区三区 | 自拍av在线| av色综合 | 亚洲草逼视频 | av老司机在线观看 | 日本一级片在线观看 | 日韩av在线第一页 | 浴室里强摁做开腿呻吟男男 | 亚洲国产毛片aaaaa无费看 | 99久久精品免费看国产四区 | 国产99视频在线 | 欧美极品少妇无套实战 | 精品国产xxx | 中国第一毛片 | 国产亚洲精品自拍 | 国产福利片在线观看 | 中文有码在线 | 男女涩涩| jizz中国少妇高潮出水 | 三级免费 | 一区二区三区精彩视频 | 看片久久| 日本黄色片 | 黄色美女免费网站 | 天天操天天操天天射 | 成人美女视频 | 苍井空浴缸大战猛男120分钟 | 国产精品刘玥久久一区 |